nvs_open_from_partition() gives ESP_ERR_NVS_NOT_FOUND

Jacek@dtm.pl
Posts: 11
Joined: Thu Jan 28, 2021 4:21 pm

nvs_open_from_partition() gives ESP_ERR_NVS_NOT_FOUND

Postby Jacek@dtm.pl » Sat Jan 15, 2022 12:21 pm

I have custom partition table with additional nvs type partition "nvs_times" and with nvs_keys type partition names "nvs_key".
In startup code i have:

Code: Select all

////////////////////////////
    //finding "nvs_key" partition
    printf("\n");
    printf("Finding nvs_key partition... ");
    esp_partition_t* partition_nvs_key;
    partition_nvs_key = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS_KEYS,"nvs_key");
    if (partition_nvs_key == NULL) 
    {
        printf("Error: nvs_key not found\n");
    }
    else
    {
        printf("nvs_key partition found\n");
    }
    //Finding  nvs_times partition
    printf("\n");
    printf("Finding nvs_times partition... ");
    esp_partition_t* partition_nvs_times;
    partition_nvs_times = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS,"nvs_times");
    if (partition_nvs_times == NULL) 
    {
        printf("Error: nvs_times partition not found\n");
    }
    else
    {
        printf("nvs_times partition found\n");
    }
    //reading configuration fom partition "nvs_key"
    nvs_sec_cfg_t sec_config;
    ret = nvs_flash_read_security_cfg(partition_nvs_key, &sec_config);
    ESP_ERROR_CHECK( ret );
    // nvs_times partition initialisation
    ret = nvs_flash_secure_init_partition("nvs_times", &sec_config);
    ESP_ERROR_CHECK( ret );
    
    // Open
    printf("\n");
    printf("Opening Non-Volatile Storage (NVS) handle... ");
    nvs_handle_t my_handle;
    char string[16] = {0}; 
    size_t string_length=0;
    ret = nvs_open_from_partition("nvs_times","times_namespace", NVS_READONLY, &my_handle);
    if (ret != ESP_OK) 
    {
        printf("Error (%s) opening NVS handle!\n", esp_err_to_name(ret));
    }
    else
    {
        printf("Done\n");

 
    }
and i have:

Code: Select all

I (885) nvs: NVS partition "nvs" is encrypted.

Finding nvs_key partition... nvs_keys partition found

Finding nvs_times partition... nvs_times partition found

Opening Non-Volatile Storage (NVS) handle... Error (ESP_ERR_NVS_NOT_FOUND) opening NVS handle!
Error (ESP_ERR_NVS_INVALID_HANDLE) reading!
I have enabled encryption and flashing pre-encrypted files.
I manually encrypt generated keys-01-13_14-23.bin before flashing and nvs_times_encr.bin partition also.
nvs_times.bin was firstly created with encrypting with generated keys-01-13_14-23.bin and than encrypted with encryption key.

Flashing like that:

Code: Select all

python esptool.py -p COM5 -b 460800 --before default_reset --after no_reset --chip esp32  write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0xb000 ../../../../ble_spp_server/build/partition_table/partition-table-encrypted.bin 0x10000 ../../../../ble_spp_server/build/ota_data_initial-encrypted.bin 0x13000 F:/GitHub/ble_spp_server/secure/partition-bin/nvs_times_encr_encrypted.bin 0x20000 ../../../../ble_spp_server/build/maxbt-encrypted.bin 0x320000 F:/GitHub/ble_spp_server/secure/nvs_key/keys/keys-01-13_14-23-encrypted.bin
What is wrong?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: nvs_open_from_partition() gives ESP_ERR_NVS_NOT_FOUND

Postby WiFive » Sat Jan 15, 2022 2:29 pm

You should not double encrypt the nvs data partition.

Jacek@dtm.pl
Posts: 11
Joined: Thu Jan 28, 2021 4:21 pm

Re: nvs_open_from_partition() gives ESP_ERR_NVS_NOT_FOUND

Postby Jacek@dtm.pl » Mon Jan 17, 2022 5:47 am

WiFive wrote:
Sat Jan 15, 2022 2:29 pm
You should not double encrypt the nvs data partition.
That's right. Thank You WiFive. Now everything works.
Thank you WiFive for being on this forum.

Who is online

Users browsing this forum: No registered users and 119 guests