From ff8f2262ef7043cf4780b80679974b5b949c7e85 Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 10 Jan 2024 20:03:41 +0000 Subject: [PATCH] 1.2.2 (#72) * added platformio CI tests * fix for platformio lib_ldf_mode deep+ and chain+ --- examples/Test_platformio/platformio.ini | 11 ++ examples/Test_platformio/src/main.cpp | 5 + library.properties | 2 +- src/ESP32-targz-lib.cpp | 4 +- src/ESP32-targz-lib.hpp | 180 ++++++++++++++++++++++-- src/ESP32-targz.h | 176 +---------------------- 6 files changed, 191 insertions(+), 187 deletions(-) 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/library.properties b/library.properties index 8f7da64..a78aea8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP32-targz -version=1.2.1 +version=1.2.2 author=tobozo maintainer=tobozo sentence=A library to unpack/uncompress tar, gz, and tar.gz files on ESP32 and ESP8266 diff --git a/src/ESP32-targz-lib.cpp b/src/ESP32-targz-lib.cpp index c1f2190..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 ) @@ -2193,7 +2193,7 @@ bool TarGzUnpacker::tarGzStreamExpander( Stream *stream, fs::FS &destFS, const c -#if defined ESP32 +#if defined ESP32 && defined HAS_OTA_SUPPORT /** GzUpdateClass Class implementation **/ diff --git a/src/ESP32-targz-lib.hpp b/src/ESP32-targz-lib.hpp index 67c915a..8247b67 100644 --- a/src/ESP32-targz-lib.hpp +++ b/src/ESP32-targz-lib.hpp @@ -37,27 +37,183 @@ \*/ -#ifndef _ESP_TGZ_H -#define _ESP_TGZ_H +#pragma once #include +#include "ESP32-targz-log.hpp" + + +#if defined ESP32 -#if defined( ESP32 ) #include #define HAS_OTA_SUPPORT -#elif defined( ESP8266 ) - //#ifdef USE_LittleFS - // #define SPIFFS LittleFS - // #include - //#endif + + // 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 - // TODO: RP2040 OTA implementation? + + #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 Unsupported architecture + + #error "Only ESP32, ESP8266 and RP2040/Pico architectures are supported" + +#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 +} + #define GZIP_DICT_SIZE 32768 #if defined ESP8266 @@ -304,7 +460,7 @@ struct TarGzUnpacker : public TarUnpacker, public GzUnpacker -#if defined ESP32 +#if defined ESP32 && defined HAS_OTA_SUPPORT // this class was inspired by https://github.com/vortigont/esp32-flashz @@ -390,4 +546,4 @@ struct TarGzUnpacker : public TarUnpacker, public GzUnpacker #include "helpers/path_tools.h" -#endif // #ifdef _ESP_TGZ_H +//#endif // #ifdef _ESP_TGZ_H diff --git a/src/ESP32-targz.h b/src/ESP32-targz.h index baed3ce..cf74dd3 100644 --- a/src/ESP32-targz.h +++ b/src/ESP32-targz.h @@ -1,179 +1,11 @@ -#ifndef _TGZ_FSFOOLS_ -#define _TGZ_FSFOOLS_ +#pragma once -// Figure out the fs::FS library to load for the **destination** filesystem +#ifdef __cplusplus - -#if defined ESP32 - - #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 - - // 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" - - #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; - - -#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 - - #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" - -#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" + #error ESP32-targz requires a C++ compiler, please change file extension to .cc or .cpp #endif