Skip to content

Commit

Permalink
1.1.7 (RP2040 support) (#62)
Browse files Browse the repository at this point in the history
* added experimental RP2040 support
* updated readme
  • Loading branch information
tobozo authored Oct 25, 2022
1 parent fba4cbc commit 69ebece
Show file tree
Hide file tree
Showing 9 changed files with 740 additions and 459 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/LibraryBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
platform-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
required-libraries: ESP32-Chimera-Core,LovyanGFX

- arduino-boards-fqbn: rp2040:rp2040:rpipico
sketch-names: Test_tar_gz_tgz.ino
platform-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

fail-fast: false

steps:
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🗜️ ESP32-targz

## An ESP32/ESP8266 Arduino library to provide decompression support for .tar, .gz and .tar.gz files
## An ESP32/ESP8266/RP2040 Arduino library to provide decompression support for .tar, .gz and .tar.gz files

[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP32-targz.svg?)](https://www.ardu-badge.com/ESP32-targz)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/tobozo/library/ESP32-targz.svg)](https://registry.platformio.org/packages/libraries/tobozo/ESP32-targz)
Expand Down Expand Up @@ -54,7 +54,8 @@ Support Matrix
| ESP32 | 1.0 | 1.0.5 | 1.0.5 | 1.0 | 1.0 |
| | | | | | |
| ESP8266 | builtin | 0.1.0 | 0.1.0 | n/a | n/a |

| | | | | | |
| RP2040 | n/a | n/a | 2.0.0 | n/a | n/a |



Expand Down
148 changes: 103 additions & 45 deletions examples/Test_tar_gz_tgz/Test_tar_gz_tgz.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,33 @@
#endif


#if defined ARDUINO_ARCH_RP2040

// SD config based on this gist: https://gist.github.com/tobozo/a68c3f37f5ed0c763e8513c11320f4fd

/*\
*
* SD Module | RP2040
* -----------+-----------
* |
* GND | GND
* 3.3v | 3V3
* CS | GPIO5
* MOSI | GPIO3
* SCK | GPIO2
* MISO | GPIO4
* |
\*/

const uint8_t SD_SCK = 2;
const uint8_t SD_MOSI = 3;
const uint8_t SD_MISO = 4;
const uint8_t SD_CS = 5;

#endif



#include "test_tools.h"

// Test #1: tarExpander()
Expand All @@ -59,7 +86,7 @@ bool test_tarExpander()
#if defined ESP32
TARUnpacker->setTarVerify( true ); // true = enables health checks but slows down the overall process
#endif
#if defined ESP8266
#if defined ESP8266 || defined ARDUINO_ARCH_RP2040
TARUnpacker->setTarVerify( false ); // true = enables health checks but slows down the overall process
#endif

Expand Down Expand Up @@ -97,7 +124,7 @@ bool test_tarStreamExpander()
#if defined ESP32
TARUnpacker->setTarVerify( true ); // true = enables health checks but slows down the overall process
#endif
#if defined ESP8266
#if defined ESP8266 || defined ARDUINO_ARCH_RP2040
TARUnpacker->setTarVerify( false ); // true = enables health checks but slows down the overall process
#endif

Expand Down Expand Up @@ -214,7 +241,7 @@ bool test_tarGzExpander()
#if defined ESP32
TARGZUnpacker->setTarVerify( true ); // true = enables health checks but slows down the overall process
#endif
#if defined ESP8266
#if defined ESP8266 || defined ARDUINO_ARCH_RP2040
TARGZUnpacker->setTarVerify( false ); // true = enables health checks but slows down the overall process
#endif
TARGZUnpacker->setupFSCallbacks( targzTotalBytesFn, targzFreeBytesFn ); // prevent the partition from exploding, recommended
Expand Down Expand Up @@ -260,7 +287,7 @@ bool test_tarGzExpander_no_intermediate()
#if defined ESP32
TARGZUnpacker->setTarVerify( true ); // true = enables health checks but slows down the overall process
#endif
#if defined ESP8266
#if defined ESP8266 || defined ARDUINO_ARCH_RP2040
TARGZUnpacker->setTarVerify( false ); // true = enables health checks but slows down the overall process
//TARGZUnpacker->setTarStatusProgressCallback( BaseUnpacker::targzNullLoggerCallback ); // print the filenames as they're expanded
#endif
Expand Down Expand Up @@ -291,48 +318,57 @@ bool test_tarGzExpander_no_intermediate()
}


#if defined HAS_OTA_SUPPORT

// Test #5: gzUpdater() and gzStreamUpdater()
// Requires: gzipped firmware file, filename must end with ".gz"
bool test_gzUpdater()
{
bool ret = false;
#if defined ESP32
const char* firmwareFile = "/firmware_example_esp32.gz";
#endif
#if defined ESP8266
const char* firmwareFile = "/firmware_example_esp8266.gz";
#endif
// Test #5: gzUpdater() and gzStreamUpdater()
// Requires: gzipped firmware file, filename must end with ".gz"
bool test_gzUpdater()
{
bool ret = false;
#if defined ESP32
const char* firmwareFile = "/firmware_example_esp32.gz";
#endif
#if defined ESP8266
const char* firmwareFile = "/firmware_example_esp8266.gz";
#endif

SerialPrintCentered("Testing gzUpdater / gzStreamUpdater", false, true );
SerialPrintCentered("Testing gzUpdater / gzStreamUpdater", false, true );

GzUnpacker *GZUnpacker = new GzUnpacker();
GzUnpacker *GZUnpacker = new GzUnpacker();

GZUnpacker->haltOnError( true ); // stop on fail (manual restart/reset required)
GZUnpacker->setupFSCallbacks( targzTotalBytesFn, targzFreeBytesFn ); // prevent the partition from exploding, recommended
GZUnpacker->setGzProgressCallback( BaseUnpacker::defaultProgressCallback ); // targzNullProgressCallback or defaultProgressCallback
GZUnpacker->setLoggerCallback( BaseUnpacker::targzPrintLoggerCallback ); // gz log verbosity
GZUnpacker->haltOnError( true ); // stop on fail (manual restart/reset required)
GZUnpacker->setupFSCallbacks( targzTotalBytesFn, targzFreeBytesFn ); // prevent the partition from exploding, recommended
GZUnpacker->setGzProgressCallback( BaseUnpacker::defaultProgressCallback ); // targzNullProgressCallback or defaultProgressCallback
GZUnpacker->setLoggerCallback( BaseUnpacker::targzPrintLoggerCallback ); // gz log verbosity

#ifdef ESP32
GZUnpacker->setPsram( true );
#endif
#ifdef ESP32
GZUnpacker->setPsram( true );
#endif

if( ! GZUnpacker->gzUpdater( sourceFS, firmwareFile, U_FLASH, /*restart on update*/false ) ) {
Serial.println( OpenLine );
SerialPrintfCentered("gzUpdater failed with return code #%d", GZUnpacker->tarGzGetError() );
Serial.println( CloseLine );
} else {
ret = true;
if( ! GZUnpacker->gzUpdater( sourceFS, firmwareFile, U_FLASH, /*restart on update*/false ) ) {
Serial.println( OpenLine );
SerialPrintfCentered("gzUpdater failed with return code #%d", GZUnpacker->tarGzGetError() );
Serial.println( CloseLine );
} else {
ret = true;
}
return ret;
}
return ret;
}

#endif

// NOT (yet?) working on ESP8266
// NOT (yet?) working on ARDUINO_ARCH_RP2040
// Test #6 tarGzStreamExpander()
// Requires: a valid stream (http or file) to a targz file
bool test_tarGzStreamExpander()
{

#if defined ARDUINO_ARCH_RP2040
// unsupported yet
SerialPrintCentered("tarGzStreamExpander not supported on RP2040", false, true );
return true;
#endif

bool ret = false;
const char* tarGzFile = "/targz_example.tar.gz";
myPackage.folder = "/"; // for md5 tests
Expand All @@ -345,7 +381,7 @@ bool test_tarGzStreamExpander()
#if defined ESP32
TARGZUnpacker->setTarVerify( true ); // true = enables health checks but slows down the overall process
#endif
#if defined ESP8266
#if defined ESP8266 || defined ARDUINO_ARCH_RP2040
TARGZUnpacker->setTarVerify( false ); // true = enables health checks but slows down the overall process
#endif
TARGZUnpacker->setupFSCallbacks( targzTotalBytesFn, targzFreeBytesFn ); // prevent the partition from exploding, recommended
Expand Down Expand Up @@ -474,6 +510,10 @@ void setup()
int max_tests = 7;
#endif

#if defined ARDUINO_ARCH_RP2040
// compensate for the dumb port detection
while(!Serial.available() ) yield();
#endif
delay(1000);
Serial.println();

Expand All @@ -484,10 +524,20 @@ void setup()
Serial.println( MiddleLine );

#if defined DEST_FS_USES_SD
#if defined ESP8266
#if defined ESP8266 // || defined ARDUINO_ARCH_RP2040
SDFSConfig sdConf(4, SD_SCK_MHZ(20) );
tarGzFS.setConfig(sdConf);
if (!tarGzFS.begin())
#elif defined ARDUINO_ARCH_RP2040
SPI.setRX( SD_MISO );
SPI.setCS( SD_CS );
SPI.setSCK( SD_SCK );
SPI.setTX( SD_MOSI );
SPI.begin();
SDFSConfig fileSystemConfig( SD_CS, SD_SCK_MHZ(20) );
// fileSystemConfig.setSPI( SPI0 ); // default is SPI0
tarGzFS.setConfig( fileSystemConfig );
if (!tarGzFS.begin())
#else // ESP32 specific SD settings
// if (!tarGzFS.begin( TFCARD_CS_PIN, 16000000 ))
if (!tarGzFS.begin())
Expand All @@ -512,12 +562,15 @@ void setup()
}
#endif


_test_begin:

if( testNum < max_tests ) {
Serial.println( MiddleLine );
SerialPrintfCentered("System Available heap: %d bytes", ESP.getFreeHeap() );
SerialPrintfCentered("System Available heap: %d bytes", HEAP_AVAILABLE() );
Serial.println( MiddleLine );

SerialPrintfCentered("ESP ready for test #%d", testNum+1 );
SerialPrintfCentered("Device ready for test #%d", testNum+1 );
Serial.println( MiddleLine );
}

Expand All @@ -535,9 +588,11 @@ void setup()
case 2: test_succeeded = test_tarGzExpander(); break;
case 3: test_succeeded = test_tarGzExpander_no_intermediate(); break;
case 4: test_succeeded = test_tarGzStreamExpander(); break;
case 5: test_succeeded = test_gzUpdater(); break;
#if defined ESP32 && !__has_include(<PSRamFS.h>)
case 6: test_succeeded = test_tarGzStreamUpdater(); break;
#if defined HAS_OTA_SUPPORT
case 5: test_succeeded = test_gzUpdater(); break;
#if defined ESP32 && !__has_include(<PSRamFS.h>)
case 6: test_succeeded = test_tarGzStreamUpdater(); break;
#endif
#endif
default:
tests_finished = true;
Expand All @@ -547,20 +602,23 @@ void setup()
if( tests_finished ) {
EEPROM.write(0, 0 );
EEPROM.commit();
#if !__has_include(<PSRamFS.h>)
BaseUnpacker *Unpacker = new BaseUnpacker();
SPIFFS.begin();
#if !__has_include(<PSRamFS.h>) && __has_include(<SPIFFS.h>)
BaseUnpacker *Unpacker = new BaseUnpacker();
SPIFFS.begin();
Unpacker->tarGzListDir( SPIFFS, "/", 3 );
#endif
SerialPrintCentered("All tests performed, press reset to restart", false, true );
}

if( test_succeeded ) {
Serial.println( OpenLine );
SerialPrintfCentered("Test #%d succeeded, will restart to proceed to the next test", testNum+1);
SerialPrintfCentered("Test #%d finished, will proceed to the next test", testNum+1);
Serial.println( CloseLine );

testNum++;
goto _test_begin;
// go on with next test
ESP.restart();
// DEVICE_RESTART();
}

}
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=ESP32-targz
version=1.1.6
version=1.1.7
author=tobozo <[email protected]>
maintainer=tobozo <[email protected]>
sentence=A library to unpack/uncompress tar, gz, and tar.gz files on ESP32 and ESP8266
paragraph=ESP32-targz is a wrapper for TinyUntar and uzLib to use with fs::FS. It supports streaming and will use ~36KB ram.
category=Data Processing
url=https://github.com/tobozo/ESP32-targz/
architectures=esp32,esp8266
architectures=esp32,esp8266,rp2040,mbed_rp2040
includes=ESP32-targz.h
Loading

0 comments on commit 69ebece

Please sign in to comment.