Hello
I was trying to use pre-encrypted nvs flash & inject initial data
I don't know what's wrong and causing the error.
Please advise
using esp-idf v4.3.1-3-g954d44c7b9-dirty
Chip is ESP32-D0WD-V3 (revision 3)
SecureBoot & Flash Encryption is enabled
print log
I (1577) nvs: nvs_key partition found
I (1587) nvs: stnv partition found
I (1587) nvs: Success to read nvs keys
I (1597) nvs: Success to secure_init_partition
Count: UsedEntries = (0), FreeEntries = (504), AllEntries = (504), NameSpaces = (0)
E (1607) nvs: nvs_open_from_partition Error (ESP_ERR_NVS_NOT_FOUND) opening NVS handle!
sdkconfig
CONFIG_NVS_ENCRYPTION=y
CONFIG_SECURE_FLASH_ENC_ENABLED=y
CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT=y
CONFIG_SECURE_BOOT=y
CONFIG_PARTITION_TABLE_CUSTOM_FILE[Codebox][/Codebox]NAME="partitions.2MB.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.2MB.csv"
esp_err_t nvs_secure_initialize() {
static const char *nvs_tag = "nvs";
esp_err_t err = ESP_OK;
// 1. find partition with nvs_keys
const esp_partition_t *key_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
ESP_PARTITION_SUBTYPE_DATA_NVS_KEYS,
"nvs_key");
if (key_partition == NULL) {
ESP_LOGE(nvs_tag, "ERROR: nvs_key partition not found");
return ESP_FAIL;
}
else {
ESP_LOGI(nvs_tag, "nvs_key partition found");
}
const esp_partition_t *stnv_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
ESP_PARTITION_SUBTYPE_DATA_NVS,
"stnv");
if (stnv_partition == NULL) {
ESP_LOGE(nvs_tag, "ERROR: stnv partition not found");
}
else{
ESP_LOGI(nvs_tag, "stnv partition found");
}
// 2. read nvs_keys from key partition
nvs_sec_cfg_t cfg;
if (ESP_OK != (err = nvs_flash_read_security_cfg(key_partition, &cfg))) {
ESP_LOGE(nvs_tag, "Failed to read nvs keys (rc=0x%x)", err);
return err;
}
else{
ESP_LOGI(nvs_tag, "Success to read nvs keys ");
}
// 3. initialize nvs partition
if (ESP_OK != (err = nvs_flash_secure_init(&cfg))) {
ESP_LOGE(nvs_tag, "failed to initialize nvs partition (err=0x%x). Aborting.", err);
return err;
}
err = nvs_flash_secure_init_partition("stnv", &cfg);
if (err != ESP_OK)
{
ESP_LOGE(nvs_tag, "failed to initialize stnv partition (err=0x%x). Aborting.", err);
}
else{
ESP_LOGI(nvs_tag, "Success to secure_init_partition ");
}
nvs_stats_t nvs_stats;
nvs_get_stats("stnv", &nvs_stats);
printf("Count: UsedEntries = (%u), FreeEntries = (%u), AllEntries = (%u), NameSpaces = (%u)\n",
nvs_stats.used_entries, nvs_stats.free_entries, nvs_stats.total_entries, nvs_stats.namespace_count);
nvs_handle_t cert_handle;
err = nvs_open_from_partition("stnv", "stdk", NVS_READONLY, &cert_handle);
if (err != ESP_OK)
{
ESP_LOGE(nvs_tag,"nvs_open_from_partition Error (%s) opening NVS handle!", esp_err_to_name(err));
}
else{
ESP_LOGI(nvs_tag, "Success to nvs_open_from_partition ");
}
size_t value_size;
err = nvs_get_str(cert_handle, "PublicKey", NULL, &value_size) ;
if (err != ESP_OK)
{
ESP_LOGE(TAG,"nvs_get_str(%s) ", esp_err_to_name(err));
return 0;
}
char *value = malloc(value_size);
if (nvs_get_str(cert_handle, "Publickey", *value, &value_size) != ESP_OK)
{
ESP_LOGE(TAG, "Failed to load key:");
return 0;
}
server_cert_len = cert_get_str(cert_handle, "PublicKey", &server_cert);
if (server_cert == NULL || server_cert_len==0)
{
ESP_LOGE(TAG,"Error! Unable to read server certificate");
}
priv_key_len = cert_get_str(cert_handle, "PrivateKey", &priv_key);
if (priv_key == NULL || priv_key_len == 0)
{
ESP_LOGE(TAG,"Error, Unable to read private key");
}
return err;
}
Can't find a nvs partition namespace
Return to “General Discussion”
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: Bing [Bot] and 100 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.