diff --git a/examples/Test_platformio/platformio.ini b/examples/Test_platformio/platformio.ini index c783ee1..78c4efe 100644 --- a/examples/Test_platformio/platformio.ini +++ b/examples/Test_platformio/platformio.ini @@ -27,6 +27,17 @@ board = esp32dev [env:esp32s3] platform = espressif32 board = esp32-s3-devkitc-1 +; Reminder: if using lib_ldf_mode deep+ or chain+, either include the undetected libraries +; from your cpp file, or add them to the lib_deps +lib_ldf_mode = chain+ +lib_deps = + SD + FS + SPI + Update + LittleFS + ESP32-targz + [env:pico] platform = https://github.com/maxgerhardt/platform-raspberrypi.git diff --git a/examples/Test_platformio/src/main.cpp b/examples/Test_platformio/src/main.cpp index 23644c5..fc8674f 100644 --- a/examples/Test_platformio/src/main.cpp +++ b/examples/Test_platformio/src/main.cpp @@ -8,6 +8,11 @@ void setup() Serial.println("Could not start filesystem"); while(1) yield(); } + + TarUnpacker *TARUnpacker = new TarUnpacker(); + GzUnpacker *GZUnpacker = new GzUnpacker(); + TarGzUnpacker *TARGZUnpacker = new TarGzUnpacker(); + } diff --git a/src/ESP32-targz-lib.cpp b/src/ESP32-targz-lib.cpp index 59548f2..e4f56e2 100644 --- a/src/ESP32-targz-lib.cpp +++ b/src/ESP32-targz-lib.cpp @@ -1567,7 +1567,7 @@ bool GzUnpacker::gzStreamExpander( Stream *stream, size_t gz_size ) -#if defined HAS_OTA_SUPPORT +#if defined ESP32 || defined ESP8266 // uncompress gz file to flash (expected to be a valid gzipped firmware) bool GzUnpacker::gzUpdater( fs::FS &fs, const char* gz_filename, int partition, bool restart_on_update ) diff --git a/src/ESP32-targz-lib.hpp b/src/ESP32-targz-lib.hpp index c454aaf..8247b67 100644 --- a/src/ESP32-targz-lib.hpp +++ b/src/ESP32-targz-lib.hpp @@ -39,11 +39,180 @@ #pragma once -#ifndef _ESP_TGZ_H - #define _ESP_TGZ_H +#include +#include "ESP32-targz-log.hpp" + + +#if defined ESP32 + + #include + #define HAS_OTA_SUPPORT + + // Figure out the chosen fs::FS library to load for the **destination** filesystem + #if defined DEST_FS_USES_SPIFFS + #include + #define tarGzFS SPIFFS + #define FS_NAME "SPIFFS" + #elif defined DEST_FS_USES_FFAT + #include + #define tarGzFS FFat + #define FS_NAME "FFAT" + #elif defined DEST_FS_USES_SD + #include + #define tarGzFS SD + #define FS_NAME "SD" + #elif defined DEST_FS_USES_SD_MMC + #include + #define tarGzFS SD_MMC + #define FS_NAME "SD_MMC" + #elif defined DEST_FS_USES_LITTLEFS + #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) + // littlefs is built-in since sdk 2.0.0 + #include + #define tarGzFS LittleFS + #define FS_NAME "LittleFS (builtin)" + #else + // get "littlefs_esp32" from library manager + #include + #define tarGzFS LITTLEFS + #define FS_NAME "LITTLEFS (extlib)" + #endif + #elif defined DEST_FS_USES_PSRAMFS + #include // https://github.com/tobozo/ESP32-PsRamFS + #define tarGzFS PSRamFS + #define FS_NAME "PSRamFS" + #else + // no filesystem, no helpers available, power user ? + #endif + +#elif defined ESP8266 + + #include + #define HAS_OTA_SUPPORT + + // ESP8266 has no SD_MMC or FFat.h library, so these are implicitely invalidated + #undef DEST_FS_USES_SD_MMC // unsupported + #undef DEST_FS_USES_FFAT // unsupported + // the fuck with spamming the console + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" + + // Figure out the chosen fs::FS library to load for the **destination** filesystem + + #if defined DEST_FS_USES_SD + #include + #define tarGzFS SDFS + #define FS_NAME "SDFS" + #else + #if defined DEST_FS_USES_LITTLEFS + #include + #define tarGzFS LittleFS + #define FS_NAME "LITTLEFS (extlib)" + #elif defined DEST_FS_USES_SPIFFS + #if defined USE_LittleFS // emulate SPIFFS using LittleFS + #include + #define tarGzFS SPIFFS + #define FS_NAME "LITTLEFS (subst)" + #else // use core SPIFFS + #define tarGzFS SPIFFS + #define FS_NAME "SPIFFS" + #endif + #else // no destination filesystem defined in sketch + #warning "Unspecified or invalid destination filesystem, please #define one of these before including the library: DEST_FS_USES_SPIFFS, DEST_FS_USES_LITTLEFS, DEST_FS_USES_SD, DEST_FS_USES_PSRAMFS" + // however, check for USE_LittleFS as it is commonly defined since SPIFFS deprecation + #if defined USE_LittleFS + #include + #define tarGzFS LittleFS + #warning "Defaulting to LittleFS" + #define DEST_FS_USES_LITTLEFS + #define FS_NAME "LITTLEFS (defaulted)" + #else + #define tarGzFS SPIFFS + #warning "Defaulting to SPIFFS (soon deprecated)" + #define DEST_FS_USES_SPIFFS + #define FS_NAME "SPIFFS" + #endif + #endif + #endif + + static FSInfo fsinfo; + +#elif defined ARDUINO_ARCH_RP2040 + + #pragma message "Experimental RP2040 support" + + #undef DEST_FS_USES_SD_MMC // unsupported + #undef DEST_FS_USES_FFAT // unsupported + #undef DEST_FS_USES_SPIFFS // unsupported + + // Figure out the chosen fs::FS library to load for the **destination** filesystem + #if defined DEST_FS_USES_SD + #include + #define tarGzFS SDFS + #define FS_NAME "SD" + #else + #include + #define tarGzFS LittleFS + #define FS_NAME "LITTLEFS (picolib)" + #endif + + static FSInfo fsinfo; + +#else + + #error "Only ESP32, ESP8266 and RP2040/Pico architectures are supported" + #endif -#include // platformio retarded lib_ldf_mode needs this even though was already included by ESP32-targz.h +#if defined DEST_FS_USES_SPIFFS || defined DEST_FS_USES_LITTLEFS || defined DEST_FS_USES_FFAT + #define WARN_LIMITED_FS +#endif + +#include // platformio whines about missing definition for 'size_t' 🤦 + +// required filesystem helpers are declared outside the main library +// because ESP32/ESP8266 use different abstraction flavours :) +__attribute__((unused)) static size_t targzFreeBytesFn() { + #if defined DEST_FS_USES_SPIFFS || defined DEST_FS_USES_SD || defined DEST_FS_USES_SD_MMC || defined DEST_FS_USES_LITTLEFS || defined DEST_FS_USES_PSRAMFS + #if defined ESP32 + return tarGzFS.totalBytes() - tarGzFS.usedBytes(); + #elif defined ESP8266 || defined ARDUINO_ARCH_RP2040 + if( tarGzFS.info( fsinfo ) ) { + return fsinfo.totalBytes - fsinfo.usedBytes; + } else { + // fail + return 0; + } + #else + #error "Only ESP32, ESP8266 and RP2040/Pico are supported" + #endif + #elif defined DEST_FS_USES_FFAT + return tarGzFS.freeBytes(); + #else + // no filesystem, no helpers available, power user ? + return 0; + #endif +} + +__attribute__((unused)) static size_t targzTotalBytesFn() { + #if defined DEST_FS_USES_SPIFFS || defined DEST_FS_USES_SD || defined DEST_FS_USES_SD_MMC || defined DEST_FS_USES_LITTLEFS || defined DEST_FS_USES_FFAT || defined DEST_FS_USES_PSRAMFS + #if defined ESP32 + return tarGzFS.totalBytes(); + #elif defined ESP8266 || defined ARDUINO_ARCH_RP2040 + if( tarGzFS.info( fsinfo ) ) { + return fsinfo.totalBytes; + } else { + // fail + return 0; + } + #else + #error "Only ESP32, ESP8266 and RP2040/Pico are supported" + #endif + #else + // no filesystem, no helpers available, power user ? + return 0; + #endif +} #define GZIP_DICT_SIZE 32768 diff --git a/src/ESP32-targz.h b/src/ESP32-targz.h index 866fd36..cf74dd3 100644 --- a/src/ESP32-targz.h +++ b/src/ESP32-targz.h @@ -1,186 +1,11 @@ #pragma once -#ifndef _TGZ_FSFOOLS_ -#define _TGZ_FSFOOLS_ -#endif - -#if defined ESP32 - - #include - #define HAS_OTA_SUPPORT - - // Figure out the chosen fs::FS library to load for the **destination** filesystem - #if defined DEST_FS_USES_SPIFFS - #include - #define tarGzFS SPIFFS - #define FS_NAME "SPIFFS" - #elif defined DEST_FS_USES_FFAT - #include - #define tarGzFS FFat - #define FS_NAME "FFAT" - #elif defined DEST_FS_USES_SD - #include - #define tarGzFS SD - #define FS_NAME "SD" - #elif defined DEST_FS_USES_SD_MMC - #include - #define tarGzFS SD_MMC - #define FS_NAME "SD_MMC" - #elif defined DEST_FS_USES_LITTLEFS - #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) - // littlefs is built-in since sdk 2.0.0 - #include - #define tarGzFS LittleFS - #define FS_NAME "LittleFS (builtin)" - #else - // get "littlefs_esp32" from library manager - #include - #define tarGzFS LITTLEFS - #define FS_NAME "LITTLEFS (extlib)" - #endif - #elif defined DEST_FS_USES_PSRAMFS - #include // https://github.com/tobozo/ESP32-PsRamFS - #define tarGzFS PSRamFS - #define FS_NAME "PSRamFS" - #else - // no filesystem, no helpers available, power user ? - #endif - -#elif defined ESP8266 - - #include - #define HAS_OTA_SUPPORT - - // ESP8266 has no SD_MMC or FFat.h library, so these are implicitely invalidated - #undef DEST_FS_USES_SD_MMC // unsupported - #undef DEST_FS_USES_FFAT // unsupported - // the fuck with spamming the console - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated-declarations" - - // Figure out the chosen fs::FS library to load for the **destination** filesystem - - #if defined DEST_FS_USES_SD - #include - #define tarGzFS SDFS - #define FS_NAME "SDFS" - #else - #if defined DEST_FS_USES_LITTLEFS - #include - #define tarGzFS LittleFS - #define FS_NAME "LITTLEFS (extlib)" - #elif defined DEST_FS_USES_SPIFFS - #if defined USE_LittleFS // emulate SPIFFS using LittleFS - #include - #define tarGzFS SPIFFS - #define FS_NAME "LITTLEFS (subst)" - #else // use core SPIFFS - #include - #define tarGzFS SPIFFS - #define FS_NAME "SPIFFS" - #endif - #else // no destination filesystem defined in sketch - #warning "Unspecified or invalid destination filesystem, please #define one of these before including the library: DEST_FS_USES_SPIFFS, DEST_FS_USES_LITTLEFS, DEST_FS_USES_SD, DEST_FS_USES_PSRAMFS" - // however, check for USE_LittleFS as it is commonly defined since SPIFFS deprecation - #if defined USE_LittleFS - #include - #define tarGzFS LittleFS - #warning "Defaulting to LittleFS" - #define DEST_FS_USES_LITTLEFS - #define FS_NAME "LITTLEFS (defaulted)" - #else - #include - #define tarGzFS SPIFFS - #warning "Defaulting to SPIFFS (soon deprecated)" - #define DEST_FS_USES_SPIFFS - #define FS_NAME "SPIFFS" - #endif - #endif - #endif - - FSInfo fsinfo; - +#ifdef __cplusplus -#elif defined ARDUINO_ARCH_RP2040 - - #pragma message "Experimental RP2040 support" - #include "ESP32-targz-log.hpp" - - #undef DEST_FS_USES_SD_MMC // unsupported - #undef DEST_FS_USES_FFAT // unsupported - #undef DEST_FS_USES_SPIFFS // unsupported - - // Figure out the chosen fs::FS library to load for the **destination** filesystem - #if defined DEST_FS_USES_SD - #include - #define tarGzFS SDFS - #define FS_NAME "SD" - #elif defined DEST_FS_USES_LITTLEFS - //#include - #include - #define tarGzFS LittleFS - #define FS_NAME "LITTLEFS (picolib)" - #else - #error "Unspecified or invalid destination filesystem, please #define one of these before including the library: DEST_FS_USES_LITTLEFS, DEST_FS_USES_SD" - #endif - - FSInfo fsinfo; + #include "ESP32-targz-lib.hpp" #else - #error "Only ESP32, ESP8266 and RP2040/Pico architectures are supported" + #error ESP32-targz requires a C++ compiler, please change file extension to .cc or .cpp #endif - - -#if defined DEST_FS_USES_SPIFFS || defined DEST_FS_USES_LITTLEFS || defined DEST_FS_USES_FFAT - #define WARN_LIMITED_FS -#endif - -#include // platformio whines about missing definition for 'size_t' 🤦 - -// required filesystem helpers are declared outside the main library -// because ESP32/ESP8266 use different abstraction flavours :) -__attribute__((unused)) static size_t targzFreeBytesFn() { - #if defined DEST_FS_USES_SPIFFS || defined DEST_FS_USES_SD || defined DEST_FS_USES_SD_MMC || defined DEST_FS_USES_LITTLEFS || defined DEST_FS_USES_PSRAMFS - #if defined ESP32 - return tarGzFS.totalBytes() - tarGzFS.usedBytes(); - #elif defined ESP8266 || defined ARDUINO_ARCH_RP2040 - if( tarGzFS.info( fsinfo ) ) { - return fsinfo.totalBytes - fsinfo.usedBytes; - } else { - // fail - return 0; - } - #else - #error "Only ESP32, ESP8266 and RP2040/Pico are supported" - #endif - #elif defined DEST_FS_USES_FFAT - return tarGzFS.freeBytes(); - #else - // no filesystem, no helpers available, power user ? - return 0; - #endif -} - -__attribute__((unused)) static size_t targzTotalBytesFn() { - #if defined DEST_FS_USES_SPIFFS || defined DEST_FS_USES_SD || defined DEST_FS_USES_SD_MMC || defined DEST_FS_USES_LITTLEFS || defined DEST_FS_USES_FFAT || defined DEST_FS_USES_PSRAMFS - #if defined ESP32 - return tarGzFS.totalBytes(); - #elif defined ESP8266 || defined ARDUINO_ARCH_RP2040 - if( tarGzFS.info( fsinfo ) ) { - return fsinfo.totalBytes; - } else { - // fail - return 0; - } - #else - #error "Only ESP32, ESP8266 and RP2040/Pico are supported" - #endif - #else - // no filesystem, no helpers available, power user ? - return 0; - #endif -} - -#include "ESP32-targz-lib.hpp"