FatFS partition of size < 1M ?

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

FatFS partition of size < 1M ?

Postby permal » Sun Dec 17, 2017 5:11 pm

Hi,

I'm in need of storing JSON <4k of data to disk. A such I wanted to create a partition with a size of 10k. However, any call to esp_vfs_fat_spiflash_mount with a partition size of less than 1M fails.

A working partition table looks like this:

Code: Select all

nvs,          data, nvs,     0x9000,  0x6000
phy_init,     data, phy,     0xf000,  0x1000
factory,      app,  factory, 0x10000, 0x150000
app_storage,  data, fat,     ,        0x100000


Removing just 4K bytes:

Code: Select all

nvs,          data, nvs,     0x9000,  0x6000
phy_init,     data, phy,     0xf000,  0x1000
factory,      app,  factory, 0x10000, 0x150000
app_storage,  data, fat,     ,        0xFF000


...causes this:

Code: Select all

E (200) wl_partition: erase_range - start_address=0x000fac00, size=0x00002000, result=0x00000102
E (206) wl_flash: initSections(257): result = 0x00000102
E (212) wl_flash: init(161): result = 0x00000102
E (218) wear_levelling: wl_mount: init instance=0x00000000, result=0x102
E (225) vfs_fat_spiflash: failed to mount wear levelling layer. result = 258
Is there a way to use fat-partitions of smaller than 1M size? I really don't want to waste nearly a mega byte for 4K of data that will be written a few times during setup then only read. I do understand that some overhead is needed to allow for wear leveling, but this much seems wasteful.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: FatFS partition of size < 1M ?

Postby loboris » Sun Dec 17, 2017 5:43 pm

Minimal FatFS partition size with 4096 bytes sector size is 512K.
Minimal FatFS partition size with 512 bytes sector size is 64K.
If you need to store such a small amount of data, maybe you could use NVS?

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: FatFS partition of size < 1M ?

Postby permal » Sun Dec 17, 2017 6:35 pm

loboris wrote:Minimal FatFS partition size with 4096 bytes sector size is 512K.
Minimal FatFS partition size with 512 bytes sector size is 64K.
If you need to store such a small amount of data, maybe you could use NVS?
If those numbers are true, then why won't my 1M - 4k partition work? Where did you get those numbers?

I could use NVS, though I'd rather work with the regular portable C-api to read and write the data. 64k would be an acceptable size if I just can get it to work.

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: FatFS partition of size < 1M ?

Postby permal » Sun Dec 17, 2017 7:01 pm

I set sector size to 512 and change the partitioning to this:

Code: Select all

nvs,          data, nvs,     0x9000,  0x6000
phy_init,     data, phy,     0xf000,  0x1000
factory,      app,  factory, 0x10000, 0x150000
app_storage,  data, fat,     ,        64k
Result:

Code: Select all

W (313) vfs_fat_spiflash: f_mount failed (13)
I (313) vfs_fat_spiflash: Formatting FATFS partition
E (313) vfs_fat_spiflash: f_mkfs failed (14)
What am I doing wrong?

Edit: Same behavior with the IDF-example for wear leveling.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: FatFS partition of size < 1M ?

Postby loboris » Sun Dec 17, 2017 7:40 pm

It looks that the minimal usable sizes are a little bigger:

512B sector - 128K

Code: Select all

I (0) cpu_start: App cpu up.
I (345) heap_init: Initializing. RAM available for dynamic allocation:
I (351) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (357) heap_init: At 3FFB9860 len 000267A0 (153 KiB): DRAM
I (364) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (370) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (376) heap_init: At 40090268 len 0000FD98 (63 KiB): IRAM
I (383) cpu_start: Pro cpu start user code
I (28) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (163) [cURL Example]: Mounting FAT filesystem
I (168) [cURL Example]: ==============
I (168) [cURL Example]: FATFS mounted.
I (168) [cURL Example]: ==============

----------------
    Sector size: 512 B
Filesystem size: 86016 B
           Used: 86016 B
           Free: 0 B
----------------
4096B sector - 528K

Code: Select all

I (0) cpu_start: App cpu up.
I (344) heap_init: Initializing. RAM available for dynamic allocation:
I (351) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (357) heap_init: At 3FFB9860 len 000267A0 (153 KiB): DRAM
I (363) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (370) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (376) heap_init: At 40090268 len 0000FD98 (63 KiB): IRAM
I (382) cpu_start: Pro cpu start user code
I (27) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (141) [cURL Example]: Mounting FAT filesystem
W (147) vfs_fat_spiflash: f_mount failed (13)
I (148) vfs_fat_spiflash: Formatting FATFS partition
I (411) vfs_fat_spiflash: Mounting again
I (411) [cURL Example]: ==============
I (411) [cURL Example]: FATFS mounted.
I (413) [cURL Example]: ==============

----------------
    Sector size: 4096 B
Filesystem size: 499712 B
           Used: 0 B
           Free: 499712 B
----------------
Tested with same partition layout as yours.

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: FatFS partition of size < 1M ?

Postby permal » Sun Dec 17, 2017 8:29 pm

Thanks loboris.

I just noticed that when executing 'make flash monitor' it doesn't always update the partition table so it seems that I've really run the same partition table layout each try... 128k/512b works for me now.

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: FatFS partition of size < 1M ?

Postby burkulesomesh43 » Sat Sep 01, 2018 2:47 pm

Hi,
I want to use only 100kb size for fat fs but it fails.

gives an error>>
20:16:41.393 -> [0;32mI (435) cpu_start: Pro cpu start user code[0m
20:16:41.393 -> [0;32mI (118) cpu_start: Starting scheduler on PRO CPU.[0m
20:16:41.393 -> [0;32mI (0) cpu_start: Starting scheduler on APP CPU.[0m
20:16:41.393 -> [0;32mI (120) file handle: Mounting FAT filesystem[0m
20:16:41.393 -> [0;31mE (120) vfs_fat_spiflash: Failed to find FATFS partition (type='data', subtype='fat', partition_label='storage'). Check the partition table.[0m
20:16:41.427 -> [0;31mE (130) file handle: Failed to mount FATFS (ESP_ERR_NOT_FOUND)[0m
--
Somesh Burkule

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: FatFS partition of size < 1M ?

Postby fly135 » Wed Nov 14, 2018 2:46 am

Just ran into this problem. I was able to fix it by changing the size of the partition from 0x80000 to 0xF0000. I figured this out partly because I was already working with 0xF0000 and that was the only thing different. I went to the IDF docs to verify this was an issue and couldn't find any mention in the documentation or the header file defining esp_vfs_fat_spiflash_mount.

I actually got alerted to check my partition size because of this line in ff.c

Code: Select all

	if (sz_vol < 128) LEAVE_MKFS(FR_MKFS_ABORTED);	/* Check if volume size is >=128s */
Even though 128 * 4096 is not less than 0x80000, it made me decide to up the partition size since I knew 0xF0000 was working in another application.

John A

Who is online

Users browsing this forum: No registered users and 96 guests