miniz library in ROM - usable for application development?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: miniz library in ROM - usable for application development?

Postby kolban » Mon Jul 09, 2018 3:30 am

Thank you sir. I resolved the issue with using the ROM based tinfl_decompress(). I coded something very stupidly. In order to create a buffer to hold the decompressed output I coded:

Code: Select all

void app_main() {
   char outputBuffer[32*1024];
   ... rest of code
}
Does everyone see my mistake above?

The answer is that I am using default ESP-IDF and the stack size of the main FreeRTOS task is 4K. As coded above, I had allocated 32K on a 4K stack. When I then called tinfl_decompress() passing in the outputBuffer as where I wanted my results to go, I was grossly exceeding stack with all manner of strange and unusual breakage.

When corrected to use a malloc() 32K from the heap, everything fell into place and all is now working. Thanks for the notes on the use of miniz in an ESP8266 environment. I had miserably failed to consider that the stub loader was used in both ESP8266 and ESP32.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
fasani
Posts: 195
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: miniz library in ROM - usable for application development?

Postby fasani » Mon May 13, 2019 7:08 am

Hello Kolban,

Would please be so kind to share this example with us ?
I've trying to load bytes of a compressed file stored in SPIFFS:

$echo "hello Fibrevillage" | gzip -cf > /data/test.gz

Then uploaded to plataformio using :
pio run --target uploadfs

Code: Select all

 if(SPIFFS.begin()) {
   Serial.print("SPIFFS.begin()");
 }
    File cmpFile = SPIFFS.open("/test.gz", FILE_READ);
    char cmpFileBuf[cmpFile.size()];
 
int filePtr=0;
 while(cmpFile.available()){
  cmpFileBuf[filePtr] = cmpFile.read();
  filePtr++;
 } 
 
 // failing on the decompress part (Just code snippet from while...loop)
 if(remaining_compressed > length) {
      flags |= TINFL_FLAG_HAS_MORE_INPUT;
    }
   status = tinfl_decompress(&inflator, (const mz_uint8 *)cmpFileBuf, &in_bytes, out_buf, next_out, &out_bytes, flags); // Dies 

But I fail in the part that is using tinfl_decompress. It could be of great help if someone can post a working example of opening a GZ from SPIFFS and successfully uncompressing it using MINIZ
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

StridingDragon
Posts: 46
Joined: Fri Aug 02, 2019 11:59 pm

Re: miniz library in ROM - usable for application development?

Postby StridingDragon » Sun Dec 04, 2022 7:47 pm

I know, this is an old thread but I just discovered it and it was super helpful! It made the migration from `ZLib` to `miniz` so easy and simple, and it worked with `libPNG` without a single hitch.

The hardest part was actually finding the correct `miniz.c` version for modification, to match the one implemented in the ROM, but if anyone is looking for it, it is actually located in `/esp-idf/components/esptool_py/esptool/flasher_stub/miniz.c`

ob_seven
Posts: 1
Joined: Tue Sep 12, 2023 12:29 pm

Re: miniz library in ROM - usable for application development?

Postby ob_seven » Tue Sep 12, 2023 1:27 pm

Thank you!

I finally discovered WHY I could not link the Miniz in ROM ...
I made the mistake to assume the full miniz was there, but I was wrong.

All was correct, except a linker error at last step in binary generation. No wonder, I was calling mz_compress and mz_uncompress which are not the low level functions.

All is clear now. Took me 3 days to understand.

I will take the Miniz.c adder code, to get the full zlib like APIs...

Who is online

Users browsing this forum: Baidu [Spider], ESP_rrtandler and 106 guests