Skip to content

SPIFFS cannot mount to a custom location in flash #1184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HuyKhac opened this issue Mar 6, 2018 · 3 comments
Closed

SPIFFS cannot mount to a custom location in flash #1184

HuyKhac opened this issue Mar 6, 2018 · 3 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@HuyKhac
Copy link

HuyKhac commented Mar 6, 2018

Hardware:

Board: ?ESP32 Dev Module?
Core Installation/update date: ?11/jul/2017?
IDE name: ?Arduino IDE? ?Platform.io? ?IDF component?
Flash Frequency: ?40Mhz?
Upload Speed: ?115200?

Description:

Hi all,
Method 1:
I use SPIFFS Arduino libraries inside my IDF project follow this example
https://github.com/espressif/arduino-esp32/blob/master/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino
When I use the code as is and run, it could mount SPIFFS and I can read/write files OK with fs::FS object. But I dont know what is the address of SPIFFS in flash memory.
The code of app_main():

extern "C" void app_main()
{
    initArduino();
   **Is_SpiFs_Init = SPIFFS.begin(true);**
  if(!Is_SpiFs_Init) Serial.println("Failed to init SPIFFS");
    //test SPIFFS
    fs::FS *fs = SPIFFS;
    File file = fs.open("/test.txt", FILE_WRITE);
    if(!file){
        Serial.println("Failed to open file for writing");
        return;
    }
    if(file.print(message)){
        Serial.println("File written");
    } else {
        Serial.println("Write failed");
    }
   //end test
  .....
}

Next I use mkspiffs.exe to build an 1MB image of SPIFFS and flash to ESP32 at location 0x110000; then I make a custom partition table to add new SPIFFS to the table

# Name,   Type, SubType, Offset,  Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1M,
storage,  data, spiffs,  0x110000, 1048576,

And rebuild the project. Now, it could not mound SPIFFS even if I call SPIFFS.begin(true)
I look to the code and see that SPIFFS.begin() calls esp_spiffs_init() which is defined in esp-idf/components/spiffs/esp_spiffs.c and in esp_spiffs_init(), it has this code:

     efs->cfg.hal_erase_f       = spiffs_api_erase;
    efs->cfg.hal_read_f        = spiffs_api_read;
    efs->cfg.hal_write_f       = spiffs_api_write;
    efs->cfg.log_block_size    = g_rom_flashchip.sector_size;
    efs->cfg.log_page_size     = log_page_size;
    **efs->cfg.phys_addr         = 0;**
    efs->cfg.phys_erase_block  = g_rom_flashchip.sector_size;
    efs->cfg.phys_size         = partition->size;

I doubt if it should set efs->cfg.phys_addr to the actual location address of SPIFFS (0x110000 in my case), not 0. Then I tried to change it to "efs->cfg.phys_addr = partition->address;" but the result is same which means it could not mount SPIFFS

Error message:
E (1014) SPIFFS: failed to read addr 001100fc, size 00000002, err 258
E (1014) SPIFFS: mount failed, -1
[E][SPIFFS.cpp:47] begin(): Mounting SPIFFS failed! Error: -1
Failed to init SPIFFS
Writing file: /index.htm
[E][vfs_api.cpp:22] open(): File system is not mounted
Failed to open file for writing
Reading file: /index.htm
[E][vfs_api.cpp:22] open(): File system is not mounted
Failed to open file for reading

Method 2:
I tried with different SPIFFS example from https://github.com/loboris/ESP32_spiffs_example and I was successful to test SPIFFS with custom location 0x110000.
However, many of my library code use the namespace fs::FS exported by SPIFFS Arduino library to access files. I dont want to manually change them to use POSIX C functions for file (fopen, fwrite, etc)

So my question is:
Why does it hardcode 0 to "efs->cfg.phys_addr"? What is the address of SPIFFS and how can I use a pre-loaded SPIFFS partition in Method 1 like I can do in Method 2?

Thanks,
HuyK

@IvanDreamer
Copy link

@HuyKhac maybe this will help:
#638 (comment)

@stale
Copy link

stale bot commented Aug 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 1, 2019
@stale
Copy link

stale bot commented Aug 15, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

2 participants