mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Merge branch 'endpoint_destrory_flash_erase' into 'main'
esp_matter: Erase endpoint_X namespace when destroying the endpoint See merge request app-frameworks/esp-matter!222
This commit is contained in:
@@ -367,6 +367,25 @@ static int get_next_index()
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
static esp_err_t erase_persistent_data(endpoint_t *endpoint)
|
||||
{
|
||||
uint16_t endpoint_id = endpoint::get_id(endpoint);
|
||||
char nvs_namespace[16] = {0};
|
||||
snprintf(nvs_namespace, 16, "endpoint_%X", endpoint_id); /* endpoint_id */
|
||||
|
||||
nvs_handle_t handle;
|
||||
esp_err_t err = nvs_open_from_partition(ESP_MATTER_NVS_PART_NAME, nvs_namespace, NVS_READWRITE, &handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error opening partition: %s, %d", nvs_namespace, err);
|
||||
return err;
|
||||
}
|
||||
err = nvs_erase_all(handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error erasing partition: %s, %d", nvs_namespace, err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t disable(endpoint_t *endpoint)
|
||||
{
|
||||
if (!endpoint) {
|
||||
@@ -431,7 +450,9 @@ static esp_err_t disable(endpoint_t *endpoint)
|
||||
/* Free endpoint type */
|
||||
free(endpoint_type);
|
||||
current_endpoint->endpoint_type = NULL;
|
||||
return ESP_OK;
|
||||
|
||||
/* Clear endpoint persistent data in nvs flash */
|
||||
return erase_persistent_data(endpoint);
|
||||
}
|
||||
|
||||
esp_err_t enable(endpoint_t *endpoint)
|
||||
@@ -933,19 +954,9 @@ esp_err_t factory_reset()
|
||||
|
||||
endpoint_t *endpoint = endpoint::get_first(node);
|
||||
while (endpoint) {
|
||||
uint16_t endpoint_id = endpoint::get_id(endpoint);
|
||||
char nvs_namespace[16] = {0};
|
||||
snprintf(nvs_namespace, 16, "endpoint_%X", endpoint_id); /* endpoint_id */
|
||||
|
||||
nvs_handle_t handle;
|
||||
err = nvs_open_from_partition(ESP_MATTER_NVS_PART_NAME, nvs_namespace, NVS_READWRITE, &handle);
|
||||
err = endpoint::erase_persistent_data(endpoint);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error opening partition: %s, %d", nvs_namespace, err);
|
||||
continue;
|
||||
}
|
||||
err = nvs_erase_all(handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error erasing partition: %s, %d", nvs_namespace, err);
|
||||
ESP_LOGE(TAG, "Error erasing persistent data of endpoint %d", endpoint::get_id(endpoint));
|
||||
continue;
|
||||
}
|
||||
endpoint = endpoint::get_next(endpoint);
|
||||
|
||||
Reference in New Issue
Block a user