Skip to content

Commit ff8f226

Browse files
authored
1.2.2 (#72)
* added platformio CI tests * fix for platformio lib_ldf_mode deep+ and chain+
1 parent a99c36e commit ff8f226

6 files changed

Lines changed: 191 additions & 187 deletions

File tree

examples/Test_platformio/platformio.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ board = esp32dev
2727
[env:esp32s3]
2828
platform = espressif32
2929
board = esp32-s3-devkitc-1
30+
; Reminder: if using lib_ldf_mode deep+ or chain+, either include the undetected libraries
31+
; from your cpp file, or add them to the lib_deps
32+
lib_ldf_mode = chain+
33+
lib_deps =
34+
SD
35+
FS
36+
SPI
37+
Update
38+
LittleFS
39+
ESP32-targz
40+
3041

3142
[env:pico]
3243
platform = https://github.com/maxgerhardt/platform-raspberrypi.git

examples/Test_platformio/src/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ void setup()
88
Serial.println("Could not start filesystem");
99
while(1) yield();
1010
}
11+
12+
TarUnpacker *TARUnpacker = new TarUnpacker();
13+
GzUnpacker *GZUnpacker = new GzUnpacker();
14+
TarGzUnpacker *TARGZUnpacker = new TarGzUnpacker();
15+
1116
}
1217

1318

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ESP32-targz
2-
version=1.2.1
2+
version=1.2.2
33
author=tobozo <tobozo@noreply.github.com>
44
maintainer=tobozo <tobozo@noreply.github.com>
55
sentence=A library to unpack/uncompress tar, gz, and tar.gz files on ESP32 and ESP8266

src/ESP32-targz-lib.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ bool GzUnpacker::gzStreamExpander( Stream *stream, size_t gz_size )
15671567

15681568

15691569

1570-
#if defined HAS_OTA_SUPPORT
1570+
#if defined ESP32 || defined ESP8266
15711571

15721572
// uncompress gz file to flash (expected to be a valid gzipped firmware)
15731573
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
21932193

21942194

21952195

2196-
#if defined ESP32
2196+
#if defined ESP32 && defined HAS_OTA_SUPPORT
21972197

21982198
/** GzUpdateClass Class implementation **/
21992199

src/ESP32-targz-lib.hpp

Lines changed: 168 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,183 @@
3737
3838
\*/
3939

40-
#ifndef _ESP_TGZ_H
41-
#define _ESP_TGZ_H
40+
#pragma once
4241

4342
#include <FS.h>
43+
#include "ESP32-targz-log.hpp"
44+
45+
46+
#if defined ESP32
4447

45-
#if defined( ESP32 )
4648
#include <Update.h>
4749
#define HAS_OTA_SUPPORT
48-
#elif defined( ESP8266 )
49-
//#ifdef USE_LittleFS
50-
// #define SPIFFS LittleFS
51-
// #include <LittleFS.h>
52-
//#endif
50+
51+
// Figure out the chosen fs::FS library to load for the **destination** filesystem
52+
#if defined DEST_FS_USES_SPIFFS
53+
#include <SPIFFS.h>
54+
#define tarGzFS SPIFFS
55+
#define FS_NAME "SPIFFS"
56+
#elif defined DEST_FS_USES_FFAT
57+
#include <FFat.h>
58+
#define tarGzFS FFat
59+
#define FS_NAME "FFAT"
60+
#elif defined DEST_FS_USES_SD
61+
#include <SD.h>
62+
#define tarGzFS SD
63+
#define FS_NAME "SD"
64+
#elif defined DEST_FS_USES_SD_MMC
65+
#include <SD_MMC.h>
66+
#define tarGzFS SD_MMC
67+
#define FS_NAME "SD_MMC"
68+
#elif defined DEST_FS_USES_LITTLEFS
69+
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
70+
// littlefs is built-in since sdk 2.0.0
71+
#include <LittleFS.h>
72+
#define tarGzFS LittleFS
73+
#define FS_NAME "LittleFS (builtin)"
74+
#else
75+
// get "littlefs_esp32" from library manager
76+
#include <LITTLEFS.h>
77+
#define tarGzFS LITTLEFS
78+
#define FS_NAME "LITTLEFS (extlib)"
79+
#endif
80+
#elif defined DEST_FS_USES_PSRAMFS
81+
#include <PSRamFS.h> // https://github.com/tobozo/ESP32-PsRamFS
82+
#define tarGzFS PSRamFS
83+
#define FS_NAME "PSRamFS"
84+
#else
85+
// no filesystem, no helpers available, power user ?
86+
#endif
87+
88+
#elif defined ESP8266
89+
5390
#include <Updater.h>
5491
#define HAS_OTA_SUPPORT
92+
93+
// ESP8266 has no SD_MMC or FFat.h library, so these are implicitely invalidated
94+
#undef DEST_FS_USES_SD_MMC // unsupported
95+
#undef DEST_FS_USES_FFAT // unsupported
96+
// the fuck with spamming the console
97+
#pragma GCC diagnostic push
98+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
99+
100+
// Figure out the chosen fs::FS library to load for the **destination** filesystem
101+
102+
#if defined DEST_FS_USES_SD
103+
#include <SD.h>
104+
#define tarGzFS SDFS
105+
#define FS_NAME "SDFS"
106+
#else
107+
#if defined DEST_FS_USES_LITTLEFS
108+
#include <LittleFS.h>
109+
#define tarGzFS LittleFS
110+
#define FS_NAME "LITTLEFS (extlib)"
111+
#elif defined DEST_FS_USES_SPIFFS
112+
#if defined USE_LittleFS // emulate SPIFFS using LittleFS
113+
#include <LittleFS.h>
114+
#define tarGzFS SPIFFS
115+
#define FS_NAME "LITTLEFS (subst)"
116+
#else // use core SPIFFS
117+
#define tarGzFS SPIFFS
118+
#define FS_NAME "SPIFFS"
119+
#endif
120+
#else // no destination filesystem defined in sketch
121+
#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"
122+
// however, check for USE_LittleFS as it is commonly defined since SPIFFS deprecation
123+
#if defined USE_LittleFS
124+
#include <LittleFS.h>
125+
#define tarGzFS LittleFS
126+
#warning "Defaulting to LittleFS"
127+
#define DEST_FS_USES_LITTLEFS
128+
#define FS_NAME "LITTLEFS (defaulted)"
129+
#else
130+
#define tarGzFS SPIFFS
131+
#warning "Defaulting to SPIFFS (soon deprecated)"
132+
#define DEST_FS_USES_SPIFFS
133+
#define FS_NAME "SPIFFS"
134+
#endif
135+
#endif
136+
#endif
137+
138+
static FSInfo fsinfo;
139+
55140
#elif defined ARDUINO_ARCH_RP2040
56-
// TODO: RP2040 OTA implementation?
141+
142+
#pragma message "Experimental RP2040 support"
143+
144+
#undef DEST_FS_USES_SD_MMC // unsupported
145+
#undef DEST_FS_USES_FFAT // unsupported
146+
#undef DEST_FS_USES_SPIFFS // unsupported
147+
148+
// Figure out the chosen fs::FS library to load for the **destination** filesystem
149+
#if defined DEST_FS_USES_SD
150+
#include <SD.h>
151+
#define tarGzFS SDFS
152+
#define FS_NAME "SD"
153+
#else
154+
#include <LittleFS.h>
155+
#define tarGzFS LittleFS
156+
#define FS_NAME "LITTLEFS (picolib)"
157+
#endif
158+
159+
static FSInfo fsinfo;
160+
57161
#else
58-
#error Unsupported architecture
162+
163+
#error "Only ESP32, ESP8266 and RP2040/Pico architectures are supported"
164+
165+
#endif
166+
167+
#if defined DEST_FS_USES_SPIFFS || defined DEST_FS_USES_LITTLEFS || defined DEST_FS_USES_FFAT
168+
#define WARN_LIMITED_FS
59169
#endif
60170

171+
#include <stddef.h> // platformio whines about missing definition for 'size_t' 🤦
172+
173+
// required filesystem helpers are declared outside the main library
174+
// because ESP32/ESP8266 <FS.h> use different abstraction flavours :)
175+
__attribute__((unused)) static size_t targzFreeBytesFn() {
176+
#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
177+
#if defined ESP32
178+
return tarGzFS.totalBytes() - tarGzFS.usedBytes();
179+
#elif defined ESP8266 || defined ARDUINO_ARCH_RP2040
180+
if( tarGzFS.info( fsinfo ) ) {
181+
return fsinfo.totalBytes - fsinfo.usedBytes;
182+
} else {
183+
// fail
184+
return 0;
185+
}
186+
#else
187+
#error "Only ESP32, ESP8266 and RP2040/Pico are supported"
188+
#endif
189+
#elif defined DEST_FS_USES_FFAT
190+
return tarGzFS.freeBytes();
191+
#else
192+
// no filesystem, no helpers available, power user ?
193+
return 0;
194+
#endif
195+
}
196+
197+
__attribute__((unused)) static size_t targzTotalBytesFn() {
198+
#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
199+
#if defined ESP32
200+
return tarGzFS.totalBytes();
201+
#elif defined ESP8266 || defined ARDUINO_ARCH_RP2040
202+
if( tarGzFS.info( fsinfo ) ) {
203+
return fsinfo.totalBytes;
204+
} else {
205+
// fail
206+
return 0;
207+
}
208+
#else
209+
#error "Only ESP32, ESP8266 and RP2040/Pico are supported"
210+
#endif
211+
#else
212+
// no filesystem, no helpers available, power user ?
213+
return 0;
214+
#endif
215+
}
216+
61217
#define GZIP_DICT_SIZE 32768
62218

63219
#if defined ESP8266
@@ -304,7 +460,7 @@ struct TarGzUnpacker : public TarUnpacker, public GzUnpacker
304460

305461

306462

307-
#if defined ESP32
463+
#if defined ESP32 && defined HAS_OTA_SUPPORT
308464

309465
// this class was inspired by https://github.com/vortigont/esp32-flashz
310466

@@ -390,4 +546,4 @@ struct TarGzUnpacker : public TarUnpacker, public GzUnpacker
390546
#include "helpers/path_tools.h"
391547

392548

393-
#endif // #ifdef _ESP_TGZ_H
549+
//#endif // #ifdef _ESP_TGZ_H

0 commit comments

Comments
 (0)