Page 1 of 1

(resolved) cannot create 4K partition

Posted: Thu Nov 08, 2018 5:28 pm
by mzimmers
Hi all...according to the docs:

https://docs.espressif.com/projects/esp ... n_gen.html

I'd expect to be able to generate a partition (.bin) file of 4096 bytes. When I run this command, however:

Code: Select all

nvs_partition_gen.py --version v2 --keygen False --encrypt False serial.csv serial.bin 0x1000
I get an error "Size parameter is insufficient."

Is this a bug in the python script, or am I missing something?

Re: cannot create 4K partition

Posted: Thu Nov 08, 2018 6:49 pm
by WiFive
Needs at least 2 sectors so 8k but it would be nice if support for read-only single sector nvs was added

Re: cannot create 4K partition

Posted: Thu Nov 08, 2018 9:54 pm
by mzimmers
Thanks for the explanation. That is disappointing, though, particularly given the apparent overhead associated with the NVS library. I mentioned in another post that I tried to store a ~1000 byte blob in a 0x2000 NVS partition, and got the error ESP_ERR_NVS_NOT_ENOUGH_SPACE, even though this was a freshly created partition. I too will look forward to the reduction of this minimum size.

Re: cannot create 4K partition

Posted: Fri Nov 09, 2018 1:52 am
by ESP_igrr
Two sectors is the minimum possible size because NVS needs to provide power off safety (data should not be lost if device is powered off during flash operation). Flash sector size is 4kB. We need one spare sector when performing flash operations, it acts as an area where data will be temporarily written while another sector is being erased.

Regarding the failure to store a 1000 byte blob, please check NVS available size before storing the blob. If you have been using Wi-Fi or Bluetooth, then PHY calibration data has also been stored in NVS, and it is about 2kB large. Wi-Fi also stores a few other configuration values. So it might be that the entire data did not fit into one sector (4K). Remember, one sector is used as a "spare" when NVS needs to erase something, so in the case when you have N sectors in NVS partition, N-1 will be actually used for data storage.

Re: cannot create 4K partition

Posted: Fri Nov 09, 2018 3:49 pm
by mzimmers
Hi Igrr...thanks for the explanation; that makes sense. I'll just not bother with a second partition, but will use "nvs" for my serialization data.

How do I go about checking the available space in the partition? I couldn't find that information on the page about the NVS library.

Re: cannot create 4K partition

Posted: Fri Nov 09, 2018 4:03 pm
by ESP_igrr
Use nvs_get_stats: https://docs.espressif.com/projects/esp ... vs_stats_t

Regarding available space, do you indeed have so little of it? You could move the beginning of app partition by 64kB, and make the size 64kB smaller. This would free up more than enough space for the second NVS partition...

Re: cannot create 4K partition

Posted: Mon Nov 12, 2018 5:35 pm
by mzimmers
I'd already looked at nvs_get_stats...the nvs_stats_t struct has 4 elements that refer to "entries."

Code: Select all

I (336) nvs: c'tor(): stats.total_entries = 504
I (336) nvs: c'tor(): stats.used_entries = 178
I (346) nvs: c'tor(): stats.free_entries = 326
I (346) nvs: c'tor(): stats.namespace_count = 4
So, do I correctly understand that the entries are 32 bytes?

Re: cannot create 4K partition

Posted: Mon Nov 12, 2018 5:46 pm
by ESP_igrr
Yes, entries are 32 bytes. Key-value pairs with integer values require 1 entry each; strings require 1 entry plus size of string divided by 32 bytes; blobs require two entries plus size of the blob divided by 32 bytes.

https://docs.espressif.com/projects/esp ... -of-a-page