Skip to content

Commit

Permalink
fix for platformio lib_ldf_mode=deep+
Browse files Browse the repository at this point in the history
  • Loading branch information
tobozo committed Jan 10, 2024
1 parent 92d9735 commit 5f6d4ac
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 182 deletions.
11 changes: 11 additions & 0 deletions examples/Test_platformio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions examples/Test_platformio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}


Expand Down
2 changes: 1 addition & 1 deletion src/ESP32-targz-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
175 changes: 172 additions & 3 deletions src/ESP32-targz-lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,180 @@

#pragma once

#ifndef _ESP_TGZ_H
#define _ESP_TGZ_H
#include <FS.h>
#include "ESP32-targz-log.hpp"


#if defined ESP32

#include <Update.h>
#define HAS_OTA_SUPPORT

// Figure out the chosen fs::FS library to load for the **destination** filesystem
#if defined DEST_FS_USES_SPIFFS
#include <SPIFFS.h>
#define tarGzFS SPIFFS
#define FS_NAME "SPIFFS"
#elif defined DEST_FS_USES_FFAT
#include <FFat.h>
#define tarGzFS FFat
#define FS_NAME "FFAT"
#elif defined DEST_FS_USES_SD
#include <SD.h>
#define tarGzFS SD
#define FS_NAME "SD"
#elif defined DEST_FS_USES_SD_MMC
#include <SD_MMC.h>
#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 <LittleFS.h>
#define tarGzFS LittleFS
#define FS_NAME "LittleFS (builtin)"
#else
// get "littlefs_esp32" from library manager
#include <LITTLEFS.h>
#define tarGzFS LITTLEFS
#define FS_NAME "LITTLEFS (extlib)"
#endif
#elif defined DEST_FS_USES_PSRAMFS
#include <PSRamFS.h> // 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 <Updater.h>
#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 <SD.h>
#define tarGzFS SDFS
#define FS_NAME "SDFS"
#else
#if defined DEST_FS_USES_LITTLEFS
#include <LittleFS.h>
#define tarGzFS LittleFS
#define FS_NAME "LITTLEFS (extlib)"
#elif defined DEST_FS_USES_SPIFFS
#if defined USE_LittleFS // emulate SPIFFS using LittleFS
#include <LittleFS.h>
#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 <LittleFS.h>
#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 <SD.h>
#define tarGzFS SDFS
#define FS_NAME "SD"
#else
#include <LittleFS.h>
#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 <FS.h> // platformio retarded lib_ldf_mode needs this even though <FS.h> 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 <stddef.h> // platformio whines about missing definition for 'size_t' 🤦

// required filesystem helpers are declared outside the main library
// because ESP32/ESP8266 <FS.h> 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

Expand Down
Loading

0 comments on commit 5f6d4ac

Please sign in to comment.