igrr / mkspiffs

Tool to build and unpack SPIFFS images

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to read file from spiffs partition

shirish47 opened this issue · comments

I wanted to use SPIFFS for storing AWS certs but I had trouble with it so I started finding what was wrong.
so I made a spiffs.bin image with mkspiffs and flashed with esptool.py and when I try to read files it shows nothing or lot of question marks.
here I have posted my first attempt to figure out where I was facing the trouble..

but then I tried given spiffs example(example works fine even if I open file and write some thing and read back it works) but if I try to read a file flashed by esptool I get nothing or ?????.

like this example I modified to read file from spiffs which is written by esptool.

    FILE* f;
    // Open file for reading
    ESP_LOGI(TAG, "Reading file");
    f = fopen("/spiffs/test.txt", "r");
    if (f == NULL) {
        ESP_LOGE(TAG, "Failed to open file for reading");
        return;
    }
    char line[64];
    fgets(line, sizeof(line), f);
    fclose(f); 

Output:

I (241) heap_init: At 40088828 len 000177D8 (93 KiB): IRAM
I (247) cpu_start: Pro cpu start user code
I (265) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (267) example: Initializing SPIFFS
I (277) example: Partition size: total: 52961, used: 6275
I (277) example: Reading file
I (277) example: Read from file: ''
I (277) example: SPIFFS unmounted

discussion going on here. https://www.esp32.com/viewtopic.php?f=2&t=4787&p=20858#p20858
I can you provide an example or spiffs.bin image and code to test with ESP32 ?

Garbage file contents usually indicates mismatch between SPIFFS configuration in mkspiffs and SPIFFS configuration in your app. In case of IDF, download mkspiffs release from releases page, which has 'esp-idf' in the archive name. Then in IDF, make sure you set SPIFFS-related sdkconfig settings to default values (specifically CONFIG_SPIFFS_META_LENGTH=4, CONFIG_SPIFFS_OBJ_NAME_LEN=32). If the values are in sync between mkspiffs and your project, you should be able to read the files.