From 8e9b852faa79d22dcd7d4a0c9f99887704b8fe14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Mon, 14 Feb 2022 18:45:29 +0100 Subject: [PATCH] Littlefs rebased to Master (#1205) * Littlefs --- .github/workflows/main_matrix.yml | 4 +- Dockerfile | 2 +- bin/build-all.sh | 10 +-- bin/build-esp32.sh | 4 +- bin/device-install.bat | 2 +- bin/device-install.sh | 2 +- bin/mklittlefs.py | 51 +++++++++++++ bin/platformio-custom.py | 3 + platformio.ini | 1 + src/FSCommon.cpp | 8 +- src/FSCommon.h | 12 +-- src/esp32/BluetoothSoftwareUpdate.cpp | 4 +- src/mesh/NodeDB.cpp | 32 ++++---- src/mesh/http/ContentHandler.cpp | 103 ++++++++++++-------------- src/mesh/http/ContentHandler.h | 14 ++-- src/mesh/mesh-pb-constants.cpp | 9 +-- src/nrf52/FS.h | 3 - src/plugins/esp32/RangeTestPlugin.cpp | 21 +++--- src/plugins/esp32/RangeTestPlugin.h | 2 +- 19 files changed, 162 insertions(+), 125 deletions(-) create mode 100755 bin/mklittlefs.py delete mode 100644 src/nrf52/FS.h diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 6703eeb78..59894f873 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -68,8 +68,8 @@ jobs: - name: Upgrade python tools and install platformio run: | python -m pip install --upgrade pip - pip install -U platformio - + pip install -U platformio + - name: Upgrade platformio run: | pio upgrade diff --git a/Dockerfile b/Dockerfile index 2f9c3a604..146ff8878 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN cd Meshtastic-device; git submodule update --init --recursive # only build the simulator RUN sed -i 's/^BOARDS_ESP32.*/BOARDS_ESP32=""/' Meshtastic-device/bin/build-all.sh RUN sed -i 's/^BOARDS_NRF52.*/BOARDS_NRF52=""/' Meshtastic-device/bin/build-all.sh -RUN sed -i 's/echo "Building SPIFFS.*/exit/' Meshtastic-device/bin/build-all.sh +RUN sed -i 's/echo "Building Filesystem.*/exit/' Meshtastic-device/bin/build-all.sh RUN . ~/.platformio/penv/bin/activate; cd Meshtastic-device; ./bin/build-all.sh CMD ["/Meshtastic-device/release/latest/bins/universal/meshtasticd_linux_amd64"] diff --git a/bin/build-all.sh b/bin/build-all.sh index fa9a85de2..07b99df90 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -76,12 +76,12 @@ do_boards "$BOARDS_NRF52" "true" pio run --environment native cp .pio/build/native/program $OUTDIR/bins/universal/meshtasticd_linux_amd64 -echo "Building SPIFFS for ESP32 targets" +echo "Building Filesystem for ESP32 targets" pio run --environment tbeam -t buildfs -cp .pio/build/tbeam/spiffs.bin $OUTDIR/bins/universal/spiffs-$VERSION.bin +cp .pio/build/tbeam/spiffs.bin $OUTDIR/bins/universal/littlefs-$VERSION.bin # keep the bins in archive also -cp $OUTDIR/bins/universal/spiffs* $OUTDIR/bins/universal/firmware* $OUTDIR/elfs/universal/firmware* $ARCHIVEDIR +cp $OUTDIR/bins/universal/littlefs* $OUTDIR/bins/universal/firmware* $OUTDIR/elfs/universal/firmware* $ARCHIVEDIR echo Updating android bins $OUTDIR/forandroid rm -rf $OUTDIR/forandroid @@ -103,9 +103,9 @@ XML echo Generating $ARCHIVEDIR/firmware-$VERSION.zip rm -f $ARCHIVEDIR/firmware-$VERSION.zip -zip --junk-paths $ARCHIVEDIR/firmware-$VERSION.zip $ARCHIVEDIR/spiffs-$VERSION.bin $OUTDIR/bins/universal/firmware-*-$VERSION.* $OUTDIR/bins/universal/meshtasticd* images/system-info.bin bin/device-install.* bin/device-update.* +zip --junk-paths $ARCHIVEDIR/firmware-$VERSION.zip $ARCHIVEDIR/littlefs-$VERSION.bin $OUTDIR/bins/universal/firmware-*-$VERSION.* $OUTDIR/bins/universal/meshtasticd* images/system-info.bin bin/device-install.* bin/device-update.* echo Generating $ARCHIVEDIR/elfs-$VERSION.zip rm -f $ARCHIVEDIR/elfs-$VERSION.zip -zip --junk-paths $ARCHIVEDIR/elfs-$VERSION.zip $OUTDIR/elfs/universal/firmware-*-$VERSION.* +zip --junk-paths $ARCHIVEDIR/elfs-$VERSION.zip $OUTDIR/elfs/universal/firmware-*-$VERSION.* echo BUILT ALL \ No newline at end of file diff --git a/bin/build-esp32.sh b/bin/build-esp32.sh index 3f87b79f3..e040ea2b5 100755 --- a/bin/build-esp32.sh +++ b/bin/build-esp32.sh @@ -34,9 +34,9 @@ echo "Copying ESP32 bin file" SRCBIN=.pio/build/$1/firmware.bin cp $SRCBIN $OUTDIR/$basename.bin -echo "Building SPIFFS for ESP32 targets" +echo "Building Filesystem for ESP32 targets" pio run --environment tbeam -t buildfs -cp .pio/build/tbeam/spiffs.bin $OUTDIR/spiffs-$VERSION.bin +cp .pio/build/tbeam/spiffs.bin $OUTDIR/littlefs-$VERSION.bin cp images/system-info.bin $OUTDIR/system-info.bin cp bin/device-install.* $OUTDIR diff --git a/bin/device-install.bat b/bin/device-install.bat index 4837d61b1..88b24fc66 100644 --- a/bin/device-install.bat +++ b/bin/device-install.bat @@ -30,7 +30,7 @@ IF EXIST %FILENAME% ( echo Trying to flash update %FILENAME%, but first erasing and writing system information" %PYTHON% -m esptool --baud 921600 erase_flash %PYTHON% -m esptool --baud 921600 write_flash 0x1000 system-info.bin - for %%f in (spiffs-*.bin) do ( + for %%f in (littlefs-*.bin) do ( %PYTHON% -m esptool --baud 921600 write_flash 0x00390000 %%f ) %PYTHON% -m esptool --baud 921600 write_flash 0x10000 %FILENAME% diff --git a/bin/device-install.sh b/bin/device-install.sh index 533361c39..c42325a0e 100755 --- a/bin/device-install.sh +++ b/bin/device-install.sh @@ -48,7 +48,7 @@ if [ -f "${FILENAME}" ]; then echo "Trying to flash ${FILENAME}, but first erasing and writing system information" "$PYTHON" -m esptool erase_flash "$PYTHON" -m esptool write_flash 0x1000 system-info.bin - "$PYTHON" -m esptool write_flash 0x00390000 spiffs-*.bin + "$PYTHON" -m esptool write_flash 0x00390000 littlefs-*.bin "$PYTHON" -m esptool write_flash 0x10000 ${FILENAME} else echo "Invalid file: ${FILENAME}" diff --git a/bin/mklittlefs.py b/bin/mklittlefs.py new file mode 100755 index 000000000..d79d5c783 --- /dev/null +++ b/bin/mklittlefs.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +import getopt +import sys +import os +from littlefs import LittleFS +from pathlib import Path + +print( "Building LittleFS image..." ) + +argList = sys.argv[1:] +arxx = { argList[i]: argList[i+1] for i in range(0, len(argList)-1, 2) } + +dataPath = arxx["-c"] +blockSize = int(arxx["-b"]) +blockCount = int(arxx["-s"]) / blockSize + +cwd = os.getcwd() + +os.chdir(dataPath) + +fileList = [] +dirList = [] + +for (dirpath, dirnames, filenames) in os.walk('.'): + for f in filenames: + if (f[:1] != '.'): + fileList.append( os.path.join(dirpath, f) ) + for d in dirnames: + if (d[:1] != '.'): + dirList.append( os.path.join(dirpath, d) ) + +fs = LittleFS(block_size=blockSize, block_count=blockCount) # create a 448kB partition + +for curDir in dirList: + print( "Creating dir " + curDir ) + fs.mkdir( curDir ) + +for curFile in fileList: + print( "Adding file " + curFile ) + with open( curFile, 'rb' ) as f: + data = f.read() + + with fs.open( curFile, 'wb') as fh: + fh.write( data ) + +outName = argList[-1] + +os.chdir(cwd) + +with open(outName, 'wb') as fh: + fh.write(fs.context.buffer) diff --git a/bin/platformio-custom.py b/bin/platformio-custom.py index d299f954f..1443f6d4f 100644 --- a/bin/platformio-custom.py +++ b/bin/platformio-custom.py @@ -6,6 +6,9 @@ import traceback import sys from readprops import readProps +Import("env") +env.Replace( MKSPIFFSTOOL=env.get("PROJECT_DIR") + '/bin/mklittlefs.py' ) + Import("projenv") prefsLoc = projenv["PROJECT_DIR"] + "/version.properties" diff --git a/platformio.ini b/platformio.ini index 946a4d063..f7974b2e6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -141,6 +141,7 @@ lib_deps = h2zero/NimBLE-Arduino@1.3.6 tobozo/ESP32-targz@^1.1.4 arduino-libraries/NTPClient#531eff39d9fbc831f3d03f706a161739203fbe2a + lorol/LittleFS_esp32@^1.0.6 # Hmm - this doesn't work yet # board_build.ldscript = linker/esp32.extram.bss.ld diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index ac87ba05a..fb3dd42fd 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -3,20 +3,20 @@ void fsInit() { -#ifdef FS - if (!FSBegin()) +#ifdef FSCom + if (!FSBegin()) { DEBUG_MSG("ERROR filesystem mount Failed\n"); assert(0); // FIXME - report failure to phone } DEBUG_MSG("Filesystem files:\n"); - File dir = FS.open("/"); + File dir = FSCom.open("/"); File f = dir.openNextFile(); while (f) { DEBUG_MSG(" %s\n", f.name()); f.close(); - f = dir.openNextFile(); + f = dir.openNextFile(); } #endif } diff --git a/src/FSCommon.h b/src/FSCommon.h index a1adb952e..be515b946 100644 --- a/src/FSCommon.h +++ b/src/FSCommon.h @@ -7,22 +7,22 @@ #ifdef PORTDUINO // Portduino version #include "PortduinoFS.h" -#define FS PortduinoFS +#define FSCom PortduinoFS #define FSBegin() true #define FILE_O_WRITE "w" #define FILE_O_READ "r" #elif !defined(NO_ESP32) // ESP32 version -#include "SPIFFS.h" -#define FS SPIFFS -#define FSBegin() FS.begin(true) +#include "LITTLEFS.h" +#define FSCom LITTLEFS +#define FSBegin() FSCom.begin(true) #define FILE_O_WRITE "w" #define FILE_O_READ "r" #else // NRF52 version #include "InternalFileSystem.h" -#define FS InternalFS -#define FSBegin() FS.begin() +#define FSCom InternalFS +#define FSBegin() FSCom.begin() using namespace Adafruit_LittleFS_Namespace; #endif diff --git a/src/esp32/BluetoothSoftwareUpdate.cpp b/src/esp32/BluetoothSoftwareUpdate.cpp index d097e95f8..4c6e94be9 100644 --- a/src/esp32/BluetoothSoftwareUpdate.cpp +++ b/src/esp32/BluetoothSoftwareUpdate.cpp @@ -104,8 +104,8 @@ int update_crc32_callback(uint16_t conn_handle, uint16_t attr_handle, struct ble } else { if (Update.end()) { if (update_region == U_SPIFFS) { - DEBUG_MSG("SPIFFS updated!\n"); - nodeDB.saveToDisk(); // Since we just wiped spiffs, we need to save our current state + DEBUG_MSG("Filesystem updated!\n"); + nodeDB.saveToDisk(); // Since we just wiped the filesystem, we need to save our current state } else { DEBUG_MSG("Appload updated, rebooting in 5 seconds!\n"); rebootAtMsec = millis() + 5000; diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 5eb8320ac..b112432e8 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1,8 +1,6 @@ #include "configuration.h" #include -#include "FS.h" - #include "Channels.h" #include "CryptoEngine.h" #include "FSCommon.h" @@ -312,16 +310,16 @@ static const char *channelfile = "/prefs/channels.proto"; /** Load a protobuf from a file, return true for success */ bool loadProto(const char *filename, size_t protoSize, size_t objSize, const pb_msgdesc_t *fields, void *dest_struct) { -#ifdef FS +#ifdef FSCom // static DeviceState scratch; We no longer read into a tempbuf because this structure is 15KB of valuable RAM - auto f = FS.open(filename); + auto f = FSCom.open(filename); // FIXME, temporary hack until every node in the universe is 1.2 or later - look for prefs in the old location (so we can // preserve region) if (!f && filename == preffile) { filename = preffileOld; - f = FS.open(filename); + f = FSCom.open(filename); } bool okay = false; @@ -374,11 +372,11 @@ void NodeDB::loadFromDisk() /** Save a protobuf from a file, return true for success */ bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_msgdesc_t *fields, const void *dest_struct) { -#ifdef FS +#ifdef FSCom // static DeviceState scratch; We no longer read into a tempbuf because this structure is 15KB of valuable RAM String filenameTmp = filename; filenameTmp += ".tmp"; - auto f = FS.open(filenameTmp.c_str(), FILE_O_WRITE); + auto f = FSCom.open(filenameTmp.c_str(), FILE_O_WRITE); bool okay = false; if (f) { DEBUG_MSG("Saving %s\n", filename); @@ -393,9 +391,9 @@ bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_ f.close(); // brief window of risk here ;-) - if (!FS.remove(filename)) + if (!FSCom.remove(filename)) DEBUG_MSG("Warning: Can't remove old pref file\n"); - if (!FS.rename(filenameTmp.c_str(), filename)) + if (!FSCom.rename(filenameTmp.c_str(), filename)) DEBUG_MSG("Error: can't rename new pref file\n"); } else { DEBUG_MSG("Can't write prefs\n"); @@ -409,8 +407,8 @@ bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_ void NodeDB::saveChannelsToDisk() { if (!devicestate.no_save) { -#ifdef FS - FS.mkdir("/prefs"); +#ifdef FSCom + FSCom.mkdir("/prefs"); #endif saveProto(channelfile, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile); } @@ -419,15 +417,15 @@ void NodeDB::saveChannelsToDisk() void NodeDB::saveToDisk() { if (!devicestate.no_save) { -#ifdef FS - FS.mkdir("/prefs"); +#ifdef FSCom + FSCom.mkdir("/prefs"); #endif saveProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); saveProto(radiofile, RadioConfig_size, sizeof(RadioConfig), RadioConfig_fields, &radioConfig); saveChannelsToDisk(); // remove any pre 1.2 pref files, turn on after 1.2 is in beta - // if(okay) FS.remove(preffileOld); + // if(okay) FSCom.remove(preffileOld); } else { DEBUG_MSG("***** DEVELOPMENT MODE - DO NOT RELEASE - not saving to flash *****\n"); } @@ -480,11 +478,11 @@ void NodeDB::updatePosition(uint32_t nodeId, const Position &p, RxSource src) if (src == RX_SRC_LOCAL) { // Local packet, fully authoritative - DEBUG_MSG("updatePosition LOCAL pos@%x:5, time=%u, latI=%d, lonI=%d\n", + DEBUG_MSG("updatePosition LOCAL pos@%x:5, time=%u, latI=%d, lonI=%d\n", p.pos_timestamp, p.time, p.latitude_i, p.longitude_i); info->position = p; - } else if ((p.time > 0) && !p.latitude_i && !p.longitude_i && !p.pos_timestamp && + } else if ((p.time > 0) && !p.latitude_i && !p.longitude_i && !p.pos_timestamp && !p.location_source) { // FIXME SPECIAL TIME SETTING PACKET FROM EUD TO RADIO // (stop-gap fix for issue #900) @@ -497,7 +495,7 @@ void NodeDB::updatePosition(uint32_t nodeId, const Position &p, RxSource src) // recorded based on the packet rxTime // // FIXME perhaps handle RX_SRC_USER separately? - DEBUG_MSG("updatePosition REMOTE node=0x%x time=%u, latI=%d, lonI=%d\n", + DEBUG_MSG("updatePosition REMOTE node=0x%x time=%u, latI=%d, lonI=%d\n", nodeId, p.time, p.latitude_i, p.longitude_i); // First, back up fields that we want to protect from overwrite diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 72755e62b..b64ea2814 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #ifndef NO_ESP32 #include "esp_task_wdt.h" @@ -46,7 +46,10 @@ using namespace httpsserver; #include HTTPClient httpClient; -#define DEST_FS_USES_SPIFFS +// needed for ESP32-targz +#define DEST_FS_USES_LITTLEFS +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +#define ESP_ARDUINO_VERSION ESP_ARDUINO_VERSION_VAL(1, 0, 4) #include // We need to specify some content-type mapping, so the resources get delivered with the @@ -127,9 +130,9 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer) ResourceNode *nodeAdmin = new ResourceNode("/admin", "GET", &handleAdmin); ResourceNode *nodeAdminSettings = new ResourceNode("/admin/settings", "GET", &handleAdminSettings); ResourceNode *nodeAdminSettingsApply = new ResourceNode("/admin/settings/apply", "POST", &handleAdminSettingsApply); - ResourceNode *nodeAdminSPIFFS = new ResourceNode("/admin/spiffs", "GET", &handleSPIFFS); - ResourceNode *nodeUpdateSPIFFS = new ResourceNode("/admin/spiffs/update", "POST", &handleUpdateSPIFFS); - ResourceNode *nodeDeleteSPIFFS = new ResourceNode("/admin/spiffs/delete", "GET", &handleDeleteSPIFFSContent); + ResourceNode *nodeAdminFs = new ResourceNode("/admin/fs", "GET", &handleFs); + ResourceNode *nodeUpdateFs = new ResourceNode("/admin/fs/update", "POST", &handleUpdateFs); + ResourceNode *nodeDeleteFs = new ResourceNode("/admin/fs/delete", "GET", &handleDeleteFsContent); ResourceNode *nodeRestart = new ResourceNode("/restart", "POST", &handleRestart); ResourceNode *nodeFormUpload = new ResourceNode("/upload", "POST", &handleFormUpload); @@ -137,8 +140,8 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer) ResourceNode *nodeJsonScanNetworks = new ResourceNode("/json/scanNetworks", "GET", &handleScanNetworks); ResourceNode *nodeJsonBlinkLED = new ResourceNode("/json/blink", "POST", &handleBlinkLED); ResourceNode *nodeJsonReport = new ResourceNode("/json/report", "GET", &handleReport); - ResourceNode *nodeJsonSpiffsBrowseStatic = new ResourceNode("/json/spiffs/browse/static", "GET", &handleSpiffsBrowseStatic); - ResourceNode *nodeJsonDelete = new ResourceNode("/json/spiffs/delete/static", "DELETE", &handleSpiffsDeleteStatic); + ResourceNode *nodeJsonFsBrowseStatic = new ResourceNode("/json/fs/browse/static", "GET", &handleFsBrowseStatic); + ResourceNode *nodeJsonDelete = new ResourceNode("/json/fs/delete/static", "DELETE", &handleFsDeleteStatic); ResourceNode *nodeRoot = new ResourceNode("/*", "GET", &handleStatic); @@ -153,13 +156,13 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer) secureServer->registerNode(nodeFormUpload); secureServer->registerNode(nodeJsonScanNetworks); secureServer->registerNode(nodeJsonBlinkLED); - secureServer->registerNode(nodeJsonSpiffsBrowseStatic); + secureServer->registerNode(nodeJsonFsBrowseStatic); secureServer->registerNode(nodeJsonDelete); secureServer->registerNode(nodeJsonReport); - secureServer->registerNode(nodeUpdateSPIFFS); - secureServer->registerNode(nodeDeleteSPIFFS); + secureServer->registerNode(nodeUpdateFs); + secureServer->registerNode(nodeDeleteFs); secureServer->registerNode(nodeAdmin); - secureServer->registerNode(nodeAdminSPIFFS); + secureServer->registerNode(nodeAdminFs); secureServer->registerNode(nodeAdminSettings); secureServer->registerNode(nodeAdminSettingsApply); secureServer->registerNode(nodeRoot); // This has to be last @@ -174,13 +177,13 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer) insecureServer->registerNode(nodeFormUpload); insecureServer->registerNode(nodeJsonScanNetworks); insecureServer->registerNode(nodeJsonBlinkLED); - insecureServer->registerNode(nodeJsonSpiffsBrowseStatic); + insecureServer->registerNode(nodeJsonFsBrowseStatic); insecureServer->registerNode(nodeJsonDelete); insecureServer->registerNode(nodeJsonReport); - insecureServer->registerNode(nodeUpdateSPIFFS); - insecureServer->registerNode(nodeDeleteSPIFFS); + insecureServer->registerNode(nodeUpdateFs); + insecureServer->registerNode(nodeDeleteFs); insecureServer->registerNode(nodeAdmin); - insecureServer->registerNode(nodeAdminSPIFFS); + insecureServer->registerNode(nodeAdminFs); insecureServer->registerNode(nodeAdminSettings); insecureServer->registerNode(nodeAdminSettingsApply); insecureServer->registerNode(nodeRoot); // This has to be last @@ -269,14 +272,14 @@ void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res) DEBUG_MSG("webAPI handleAPIv1ToRadio\n"); } -void handleSpiffsBrowseStatic(HTTPRequest *req, HTTPResponse *res) +void handleFsBrowseStatic(HTTPRequest *req, HTTPResponse *res) { res->setHeader("Content-Type", "application/json"); res->setHeader("Access-Control-Allow-Origin", "*"); res->setHeader("Access-Control-Allow-Methods", "GET"); - File root = SPIFFS.open("/"); + File root = FSCom.open("/"); if (root.isDirectory()) { res->println("{"); @@ -313,9 +316,9 @@ void handleSpiffsBrowseStatic(HTTPRequest *req, HTTPResponse *res) } res->print("],"); res->print("\"filesystem\" : {"); - res->print("\"total\" : " + String(SPIFFS.totalBytes()) + ","); - res->print("\"used\" : " + String(SPIFFS.usedBytes()) + ","); - res->print("\"free\" : " + String(SPIFFS.totalBytes() - SPIFFS.usedBytes())); + res->print("\"total\" : " + String(FSCom.totalBytes()) + ","); + res->print("\"used\" : " + String(FSCom.usedBytes()) + ","); + res->print("\"free\" : " + String(FSCom.totalBytes() - FSCom.usedBytes())); res->println("}"); res->println("},"); res->println("\"status\": \"ok\""); @@ -323,7 +326,7 @@ void handleSpiffsBrowseStatic(HTTPRequest *req, HTTPResponse *res) } } -void handleSpiffsDeleteStatic(HTTPRequest *req, HTTPResponse *res) +void handleFsDeleteStatic(HTTPRequest *req, HTTPResponse *res) { ResourceParameters *params = req->getParams(); std::string paramValDelete; @@ -333,7 +336,7 @@ void handleSpiffsDeleteStatic(HTTPRequest *req, HTTPResponse *res) res->setHeader("Access-Control-Allow-Methods", "DELETE"); if (params->getQueryParameter("delete", paramValDelete)) { std::string pathDelete = "/" + paramValDelete; - if (SPIFFS.remove(pathDelete.c_str())) { + if (FSCom.remove(pathDelete.c_str())) { Serial.println(pathDelete.c_str()); res->println("{"); res->println("\"status\": \"ok\""); @@ -361,18 +364,18 @@ void handleStatic(HTTPRequest *req, HTTPResponse *res) std::string filename = "/static/" + parameter1; std::string filenameGzip = "/static/" + parameter1 + ".gz"; - // Try to open the file from SPIFFS + // Try to open the file File file; bool has_set_content_type = false; - if (SPIFFS.exists(filename.c_str())) { - file = SPIFFS.open(filename.c_str()); + if (FSCom.exists(filename.c_str())) { + file = FSCom.open(filename.c_str()); if (!file.available()) { DEBUG_MSG("File not available - %s\n", filename.c_str()); } - } else if (SPIFFS.exists(filenameGzip.c_str())) { - file = SPIFFS.open(filenameGzip.c_str()); + } else if (FSCom.exists(filenameGzip.c_str())) { + file = FSCom.open(filenameGzip.c_str()); res->setHeader("Content-Encoding", "gzip"); if (!file.available()) { DEBUG_MSG("File not available - %s\n", filenameGzip.c_str()); @@ -380,7 +383,7 @@ void handleStatic(HTTPRequest *req, HTTPResponse *res) } else { has_set_content_type = true; filenameGzip = "/static/index.html.gz"; - file = SPIFFS.open(filenameGzip.c_str()); + file = FSCom.open(filenameGzip.c_str()); res->setHeader("Content-Type", "text/html"); if (!file.available()) { DEBUG_MSG("File not available - %s\n", filenameGzip.c_str()); @@ -410,7 +413,7 @@ void handleStatic(HTTPRequest *req, HTTPResponse *res) res->setHeader("Content-Type", "application/octet-stream"); } - // Read the file from SPIFFS and write it to the HTTP response body + // Read the file and write it to the HTTP response body size_t length = 0; do { char buffer[256]; @@ -502,20 +505,12 @@ void handleFormUpload(HTTPRequest *req, HTTPResponse *res) return; } - // SPIFFS limits the total lenth of a path + file to 31 characters. - if (filename.length() + 8 > 31) { - DEBUG_MSG("Uploaded filename too long!\n"); - res->println("

Uploaded filename too long! Limit of 23 characters.

"); - delete parser; - return; - } - // You should check file name validity and all that, but we skip that to make the core // concepts of the body parser functionality easier to understand. std::string pathname = "/static/" + filename; - // Create a new file on spiffs to stream the data into - File file = SPIFFS.open(pathname.c_str(), "w"); + // Create a new file to stream the data into + File file = FSCom.open(pathname.c_str(), "w"); size_t fileLength = 0; didwrite = true; @@ -529,7 +524,7 @@ void handleFormUpload(HTTPRequest *req, HTTPResponse *res) // DEBUG_MSG("\n\nreadLength - %i\n", readLength); // Abort the transfer if there is less than 50k space left on the filesystem. - if (SPIFFS.totalBytes() - SPIFFS.usedBytes() < 51200) { + if (FSCom.totalBytes() - FSCom.usedBytes() < 51200) { file.close(); res->println("

Write aborted! Reserving 50k on filesystem.

"); @@ -649,9 +644,9 @@ void handleReport(HTTPRequest *req, HTTPResponse *res) res->printf("\"heap_free\": %d,\n", ESP.getFreeHeap()); res->printf("\"psram_total\": %d,\n", ESP.getPsramSize()); res->printf("\"psram_free\": %d,\n", ESP.getFreePsram()); - res->println("\"spiffs_total\" : " + String(SPIFFS.totalBytes()) + ","); - res->println("\"spiffs_used\" : " + String(SPIFFS.usedBytes()) + ","); - res->println("\"spiffs_free\" : " + String(SPIFFS.totalBytes() - SPIFFS.usedBytes())); + res->println("\"fs_total\" : " + String(FSCom.totalBytes()) + ","); + res->println("\"fs_used\" : " + String(FSCom.usedBytes()) + ","); + res->println("\"fs_free\" : " + String(FSCom.totalBytes() - FSCom.usedBytes())); res->println("},"); res->println("\"power\": {"); @@ -699,7 +694,7 @@ void handleHotspot(HTTPRequest *req, HTTPResponse *res) res->println("\n"); } -void handleUpdateSPIFFS(HTTPRequest *req, HTTPResponse *res) +void handleUpdateFs(HTTPRequest *req, HTTPResponse *res) { res->setHeader("Content-Type", "text/html"); res->setHeader("Access-Control-Allow-Origin", "*"); @@ -716,7 +711,7 @@ void handleUpdateSPIFFS(HTTPRequest *req, HTTPResponse *res) if (streamptr != nullptr) { DEBUG_MSG("Connection to content server ... success!\n"); - File root = SPIFFS.open("/"); + File root = FSCom.open("/"); File file = root.openNextFile(); DEBUG_MSG("Deleting files from /static : \n"); @@ -725,7 +720,7 @@ void handleUpdateSPIFFS(HTTPRequest *req, HTTPResponse *res) String filePath = String(file.name()); if (filePath.indexOf("/static") == 0) { DEBUG_MSG(" %s\n", file.name()); - SPIFFS.remove(file.name()); + FSCom.remove(file.name()); } file = root.openNextFile(); } @@ -752,7 +747,7 @@ void handleUpdateSPIFFS(HTTPRequest *req, HTTPResponse *res) res->printf("Stream size %d

\n", streamSize); } - if (!TARUnpacker->tarStreamExpander(streamptr, streamSize, SPIFFS, "/static")) { + if (!TARUnpacker->tarStreamExpander(streamptr, streamSize, FSCom, "/static")) { res->printf("tarStreamExpander failed with return code #%d\n", TARUnpacker->tarGzGetError()); Serial.printf("tarStreamExpander failed with return code #%d\n", TARUnpacker->tarGzGetError()); @@ -786,16 +781,16 @@ void handleUpdateSPIFFS(HTTPRequest *req, HTTPResponse *res) webServerThread->requestRestart = (millis() / 1000) + 5; } -void handleDeleteSPIFFSContent(HTTPRequest *req, HTTPResponse *res) +void handleDeleteFsContent(HTTPRequest *req, HTTPResponse *res) { res->setHeader("Content-Type", "text/html"); res->setHeader("Access-Control-Allow-Origin", "*"); res->setHeader("Access-Control-Allow-Methods", "GET"); res->println("

Meshtastic

\n"); - res->println("Deleting SPIFFS Content in /static/*"); + res->println("Deleting Content in /static/*"); - File root = SPIFFS.open("/"); + File root = FSCom.open("/"); File file = root.openNextFile(); DEBUG_MSG("Deleting files from /static : \n"); @@ -804,7 +799,7 @@ void handleDeleteSPIFFSContent(HTTPRequest *req, HTTPResponse *res) String filePath = String(file.name()); if (filePath.indexOf("/static") == 0) { DEBUG_MSG(" %s\n", file.name()); - SPIFFS.remove(file.name()); + FSCom.remove(file.name()); } file = root.openNextFile(); } @@ -819,7 +814,7 @@ void handleAdmin(HTTPRequest *req, HTTPResponse *res) res->println("

Meshtastic

\n"); res->println("Settings
\n"); - res->println("Manage Web Content
\n"); + res->println("Manage Web Content
\n"); res->println("Device Report
\n"); } @@ -859,14 +854,14 @@ void handleAdminSettingsApply(HTTPRequest *req, HTTPResponse *res) } -void handleSPIFFS(HTTPRequest *req, HTTPResponse *res) +void handleFs(HTTPRequest *req, HTTPResponse *res) { res->setHeader("Content-Type", "text/html"); res->setHeader("Access-Control-Allow-Origin", "*"); res->setHeader("Access-Control-Allow-Methods", "GET"); res->println("

Meshtastic

\n"); - res->println("Delete Web Content

println("Delete Web Content

Be patient!"); res->println("


Back to admin\n"); } diff --git a/src/mesh/http/ContentHandler.h b/src/mesh/http/ContentHandler.h index c3babdd72..278b923ed 100644 --- a/src/mesh/http/ContentHandler.h +++ b/src/mesh/http/ContentHandler.h @@ -11,13 +11,13 @@ void handleStatic(HTTPRequest *req, HTTPResponse *res); void handleRestart(HTTPRequest *req, HTTPResponse *res); void handleFormUpload(HTTPRequest *req, HTTPResponse *res); void handleScanNetworks(HTTPRequest *req, HTTPResponse *res); -void handleSpiffsBrowseStatic(HTTPRequest *req, HTTPResponse *res); -void handleSpiffsDeleteStatic(HTTPRequest *req, HTTPResponse *res); +void handleFsBrowseStatic(HTTPRequest *req, HTTPResponse *res); +void handleFsDeleteStatic(HTTPRequest *req, HTTPResponse *res); void handleBlinkLED(HTTPRequest *req, HTTPResponse *res); void handleReport(HTTPRequest *req, HTTPResponse *res); -void handleUpdateSPIFFS(HTTPRequest *req, HTTPResponse *res); -void handleDeleteSPIFFSContent(HTTPRequest *req, HTTPResponse *res); -void handleSPIFFS(HTTPRequest *req, HTTPResponse *res); +void handleUpdateFs(HTTPRequest *req, HTTPResponse *res); +void handleDeleteFsContent(HTTPRequest *req, HTTPResponse *res); +void handleFs(HTTPRequest *req, HTTPResponse *res); void handleAdmin(HTTPRequest *req, HTTPResponse *res); void handleAdminSettings(HTTPRequest *req, HTTPResponse *res); void handleAdminSettingsApply(HTTPRequest *req, HTTPResponse *res); @@ -34,9 +34,7 @@ class HttpAPI : public PhoneAPI // Nothing here yet protected: - + /// Check the current underlying physical link to see if the client is currently connected virtual bool checkIsConnected() override { return true; } // FIXME, be smarter about this }; - - diff --git a/src/mesh/mesh-pb-constants.cpp b/src/mesh/mesh-pb-constants.cpp index e7ccf45a3..5e901c799 100644 --- a/src/mesh/mesh-pb-constants.cpp +++ b/src/mesh/mesh-pb-constants.cpp @@ -1,16 +1,11 @@ #include "mesh-pb-constants.h" -#include "FS.h" +#include "FSCommon.h" #include "configuration.h" #include #include #include #include -#ifdef ARDUINO_ARCH_NRF52 -#include "Adafruit_LittleFS.h" -using namespace Adafruit_LittleFS_Namespace; // To get File type -#endif - /// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic /// returns the encoded packet size size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc_t *fields, const void *src_struct) @@ -72,4 +67,4 @@ bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count) return true; return false; -} \ No newline at end of file +} diff --git a/src/nrf52/FS.h b/src/nrf52/FS.h deleted file mode 100644 index 819693660..000000000 --- a/src/nrf52/FS.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -// FIXME - make a FS abstraction for NRF52 \ No newline at end of file diff --git a/src/plugins/esp32/RangeTestPlugin.cpp b/src/plugins/esp32/RangeTestPlugin.cpp index 5f845a253..5e7238fa5 100644 --- a/src/plugins/esp32/RangeTestPlugin.cpp +++ b/src/plugins/esp32/RangeTestPlugin.cpp @@ -8,13 +8,12 @@ #include "configuration.h" #include "gps/GeoCoord.h" #include -#include +#include //#include /* As a sender, I can send packets every n-seonds. These packets include an incramented PacketID. - - As a receiver, I can receive packets from multiple senders. These packets can be saved to the spiffs. + As a receiver, I can receive packets from multiple senders. These packets can be saved to the Filesystem. */ RangeTestPlugin *rangeTestPlugin; @@ -214,20 +213,20 @@ bool RangeTestPluginRadio::appendFile(const MeshPacket &mp) DEBUG_MSG("gpsStatus->getDOP() %d\n", gpsStatus->getDOP()); DEBUG_MSG("-----------------------------------------\n"); */ - if (!SPIFFS.begin(true)) { - DEBUG_MSG("An Error has occurred while mounting SPIFFS\n"); + if (!FSBegin()) { + DEBUG_MSG("An Error has occurred while mounting the filesystem\n"); return 0; } - if (SPIFFS.totalBytes() - SPIFFS.usedBytes() < 51200) { - DEBUG_MSG("SPIFFS doesn't have enough free space. Abourting write.\n"); + if (FSCom.totalBytes() - FSCom.usedBytes() < 51200) { + DEBUG_MSG("Filesystem doesn't have enough free space. Aborting write.\n"); return 0; } // If the file doesn't exist, write the header. - if (!SPIFFS.exists("/static/rangetest.csv")) { + if (!FSCom.exists("/static/rangetest.csv")) { //--------- Write to file - File fileToWrite = SPIFFS.open("/static/rangetest.csv", FILE_WRITE); + File fileToWrite = FSCom.open("/static/rangetest.csv", FILE_WRITE); if (!fileToWrite) { DEBUG_MSG("There was an error opening the file for writing\n"); @@ -245,8 +244,8 @@ bool RangeTestPluginRadio::appendFile(const MeshPacket &mp) fileToWrite.close(); } - //--------- Apend content to file - File fileToAppend = SPIFFS.open("/static/rangetest.csv", FILE_APPEND); + //--------- Append content to file + File fileToAppend = FSCom.open("/static/rangetest.csv", FILE_APPEND); if (!fileToAppend) { DEBUG_MSG("There was an error opening the file for appending\n"); diff --git a/src/plugins/esp32/RangeTestPlugin.h b/src/plugins/esp32/RangeTestPlugin.h index e79f0e072..5e7d7da16 100644 --- a/src/plugins/esp32/RangeTestPlugin.h +++ b/src/plugins/esp32/RangeTestPlugin.h @@ -36,7 +36,7 @@ class RangeTestPluginRadio : public SinglePortPlugin void sendPayload(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); /** - * Append range test data to the file on the spiffs + * Append range test data to the file on the Filesystem */ bool appendFile(const MeshPacket &mp);