NVS Key values pairs

atique
Posts: 4
Joined: Thu Sep 05, 2024 3:28 pm

NVS Key values pairs

Postby atique » Thu Sep 05, 2024 3:43 pm

Hi All,
I have problem in reading the nvs_keys partition when its flashed with existing binary files. let me describe it in the following steps:
1 - I have a requirement where some default keys are needed as part of the firmware initial process
2 - All keys were created with a firmware have default values
3 - Read back the nvs_key partition using the `parttool.py --port "COM1" read_partition --partition-type=data --partition-subtype=nvs_keys --output "nvs_keys.bin"`
4 - After this all flash is erased and as part of board programming process `nvs_keys.bin` is flashed using the parttool
5 - So far so good everything is working and firmware is running but when it comes to reading the NKS Keys, firmware return as those default kays does not even exist in nvs_key partition while reading the nvs_key partion return the same binary as it was written

Is there something that needs to be done as part of this process or am I missing some steps?
Thanks

ESP_Sprite
Posts: 9568
Joined: Thu Nov 26, 2015 4:08 am

Re: NVS Key values pairs

Postby ESP_Sprite » Fri Sep 06, 2024 2:09 am

Not sure what's wrong, but the canonical way to do this is to use the esp-idf build system to generate the partition so you're sure you have an entirely clean one. Perhaps try that?

chegewara
Posts: 2306
Joined: Wed Jun 14, 2017 9:00 pm

Re: NVS Key values pairs

Postby chegewara » Fri Sep 06, 2024 2:17 am

Did you try this tool?
https://github.com/espressif/esp-idf-nvs-partition-gen

It is easy way to build manufacturing partition with values you want.

Also, can you post partition table you are using?

atique
Posts: 4
Joined: Thu Sep 05, 2024 3:28 pm

Re: NVS Key values pairs

Postby atique » Fri Sep 06, 2024 8:16 am

@ ESP_Sprite Yes I have tried to use that build system to generate the partition but the default size for the partition in build system is 0x3000 while my partition size is just 0x1000. I have generated the partition using the build system and obviously it was failure while flashing to the board due to size issue. Also as a next step I have compared the generated partition and read back partition they appear to be same upto address 4096.
@chegewara Here is the partition table i am using is:
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x4000
otadata, data, ota, 0xd000, 0x2000
phy_init, data, phy, 0xf000, 0x1000
ota_0, app, ota_0, , 0x180000
ota_1, app, ota_1, , 0x180000
nvs_key, data, nvs_keys, , 0x1000

ESP_Sprite
Posts: 9568
Joined: Thu Nov 26, 2015 4:08 am

Re: NVS Key values pairs

Postby ESP_Sprite » Fri Sep 06, 2024 10:13 am

atique wrote:
Fri Sep 06, 2024 8:16 am
while my partition size is just 0x1000.
That may be your problem: NVS needs at least 3 sectors and you're only giving it one.

DrMickeyLauer
Posts: 163
Joined: Sun May 22, 2022 2:42 pm

Re: NVS Key values pairs

Postby DrMickeyLauer » Fri Sep 06, 2024 11:21 am

ESP_Sprite wrote:
Fri Sep 06, 2024 10:13 am
atique wrote:
Fri Sep 06, 2024 8:16 am
while my partition size is just 0x1000.
That may be your problem: NVS needs at least 3 sectors and you're only giving it one.
Is this requirement documented?

ESP_Sprite
Posts: 9568
Joined: Thu Nov 26, 2015 4:08 am

Re: NVS Key values pairs

Postby ESP_Sprite » Sat Sep 07, 2024 6:48 am

Doesn't look like it. I'll file an internal issue.

atique
Posts: 4
Joined: Thu Sep 05, 2024 3:28 pm

Re: NVS Key values pairs

Postby atique » Mon Sep 09, 2024 1:53 pm

ESP_Sprite wrote:
Fri Sep 06, 2024 10:13 am
atique wrote:
Fri Sep 06, 2024 8:16 am
while my partition size is just 0x1000.
That may be your problem: NVS needs at least 3 sectors and you're only giving it one.
I will verify this by changing the partition table size.

atique
Posts: 4
Joined: Thu Sep 05, 2024 3:28 pm

Re: NVS Key values pairs

Postby atique » Thu Sep 12, 2024 8:17 am

ESP_Sprite wrote:
Fri Sep 06, 2024 10:13 am
atique wrote:
Fri Sep 06, 2024 8:16 am
while my partition size is just 0x1000.
That may be your problem: NVS needs at least 3 sectors and you're only giving it one.
This does not seems to be the issue. I have updated the partition table allocating 3 sectors to nvs_key partition and still I am getting the same result.

Who is online

Users browsing this forum: Dominikzz and 48 guests