espressif / esp-at

AT application for ESP32/ESP32-C2/ESP32-C3/ESP32-C6/ESP8266
Apache License 2.0
847 stars 710 forks source link

Enabling flash encryption with ESP-AT result in a missing partition error. #818

Open charmed12 opened 3 months ago

charmed12 commented 3 months ago

Answers checklist.

General issue report

Hi,

I would like to activate flash encryption on the ESP32 WROOM module. I have successfully enabled it using the Menuconfig in development mode. Additionally, I have configured the log bootloader to none and enabled the bootloader to optimize size. Here is the partition table:

Name, Type, SubType, Offset, Size, Flags

phy_init, data, phy, 0x10000, 0x1000, encrypted otadata, data, ota, 0x11000, 0x2000, encrypted nvs, data, nvs, 0x13000, 50K at_customize, 0x40, 0, 0x20000, 0xE0000 ota_0, app, ota_0, 0x100000, 0x180000, encrypted ota_1, app, ota_1, 0x280000, 0x180000, encrypted

Name, Type, SubType, Offset, Size, Flags

mfg_nvs, data, nvs, 0x21000, 112K,encrypted fatfs, data, fat, 0x70000, 576K, encrypted

I deleted all OTA partitions. I encountered an issue where the factory_param partition was missing. I conducted tests on some AT commands which were successful, however, I encountered errors when trying to use AT+sysflash, AT+BLEGATTSSRVCRE, and AT+BLEGATTSSRVSTART. I must resolve this issue promptly as I need to flash the ble_data partition via the AT command.

After debugging the esp-at code i notice that const esp_partition_t *partition = esp_at_custom_partition_find(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, g_at_mfg_nvs_name); can't find the g_at_mfg_nvs_name and factory_param partition, even if at_customize is not encrypted and others partitions are encrypted i got the same resualt. esp_at_custom_partition_find. i'm asking if there is any solutions to encrypt nvs partition, and use gatt server (ble_data partition) on esp-at FW ? Or how to resolve this issue? Thank you (I tested on v4.0.0 ,v3.2.0.0 and 2.1.0.0) esp32 Wroom

ustccw commented 2 months ago

esp_at_custom_partition_find(type, subtype, label); will call esp_partition_find_first(0x40, 0, "at_customize"); to get the information of secondary partition table (at_customize.bin), and find the label == "mfg_nvs", could you please add more debug info in esp_partition_find_first().

The factory_param namespace belongs to mfg_nvs partition, and mfg_nvs partition is initialized as nvs by nvs_flash_init_partition_ptr(). Since this partition is encrypted, you have to initialize this partition as nvs by nvs_flash_secure_init_partition() related APIs, so that the following nvs_open_from_partition() related APIs can fetch the right data.