Mutiple FAT partitions on esp32

I want to use two fat partitions on my esp32. I have already created the two partitions with the partition table.

Until now I had only one partition, which I mounted with the FFat library very simple with FFat.begin().
Now I would like to create an instance for each partition. So for example FFat1 and FFat2.

Unfortunately it is not clear to me how I can achieve this or if there is another way to be able to read and write files on the two partitions separately.

For tips and hints I would be very grateful.

The first thing that occurs to me is why you need 2 partitions

Please post your sketch that uses one partition, using < CODE/ > tags when you do

I need a partition where I can ensure that there is always enough memory to store a bin file for a firmware update.

The other partition is for all other data. Webserver files, configurations etc.

So far I have only used one partition, which I simply mounted in setup with
FFat.begin()

To read and write files I just used the function
FFat.open()

What I would like to achieve is something like this
FFat1.begin();
FFat2.begin();

So that I have separate access to the files in the two partitions.

Why would you use a filesystem to hold a single binary image file? Just write it directly to the FLASH partition, starting at offset 0 in the partition. The filesystem is just overhead that adds no value.

Please post a complete sketch that shows the use of the FFat library

It's all a bit more coplicitous. The firmware file is encrypted and therefore cannot be written directly into flash. To ensure that I am always able to download and store a large encrypted firmware file, I want to reserve space for this purpose.

A file is a file. It's just a sequence of bytes of data. How does being encrypted affect anything at all? When you write a file to a FAT filesystem, it writes those bytes to FLASH without changing them in any way.

Sure, but I need to manipulate the file before writing the update to flash. The encrypted firmware image would not boot.

But that ist not the point.
I would like to know how to create mutiple instances of FFat.
The begin() function has a parameter to select the partition label to mount. But I dont know how to use both partitions because I have just one instance of FFat.

Please post a complete sketch that shows the use of the FFat library

I cant provide the full sketch. The sketch is way to big.
But there is not really more to it than including the library and mounting the partition with
#include "FFat.h"

void setup() {
FFat.begin(false, "/ffat", (uint8_t)10U, "ffat");
}

and opening a file to read or write with
File myFile = FFat.open(filepath, mode);

It looks like your FFat library does not support multiple instances.

I'd write a special file to the file system, large enough for an update. Then rewrite that file whenever an update is downloaded.

Each instance of the file system on the esp32 would be given the same memory area to use, as per post#10, not possible.

But,

If your ESP32 has PSRAM, you can write to multiple locations as separate entities but not using a file system. One would use the ESP32's API to use the HiMem. Also under the Arduino IDE the code can only access 4MB of PSRAM, if you want to access more, one would have to use the ESPRESSIF's IDF.

It has been a while since I researched this for another post; but it is my understanding that multiple partitions are not supported.

I think you are right. I have not been able to get it to work with multiple instances.
But it works for me to unmount the data partition and mount the update partition when I need to work on the update partition. This probably saves some resources on my esp32 as well.

Thanks to all of you for your input. The problem is now solved for me.

Another solution I have found is to use the FFat library for my data partition and mount the update partition with the tools of the esp-idf functions.

#include "vfs_api.h"
extern "C" {
#include "esp_vfs_fat.h"
#include "diskio.h"
#include "diskio_wl.h"
#include "vfs_fat_internal.h"
}
#include "wear_levelling.h"

#define MOUNT_POINT_0 "/storage"
#define MOUNT_POINT_1 "/update"
#define PARTITION_LABEL_0 "storage"
#define PARTITION_LABEL_1 "update"

wl_handle_t wl_handle_update = WL_INVALID_HANDLE;

void setup() {
FFat.begin(true, MOUNT_POINT_0, (uint8_t)10U, PARTITION_LABEL_0);

esp_vfs_fat_mount_config_t conf = {
.format_if_mount_failed = true,
.max_files = 4,
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE
};
esp_err_t err = esp_vfs_fat_spiflash_mount(MOUNT_POINT_1, PARTITION_LABEL_1, &conf, &wl_handle_update);
if (err) {
log_e("Mounting FFat partition failed! Error: %d", err);
esp_vfs_fat_spiflash_unmount(MOUNT_POINT_1, wl_handle_update);
wl_handle_update = WL_INVALID_HANDLE;
}
}

Then I can use File myDataFile = FFat.open(filepath) for my data files
and FILE* myUpdateFile = fopen(filepath) for my update files.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.