Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented esp_core_dump_image_erase() (IDFGH-4832) #6631

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions components/espcoredump/include/esp_core_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,13 @@ void esp_core_dump_to_uart(panic_info_t *info);
*/
esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size);

/**
* @brief Erases coredump data in flash. esp_core_dump_image_get() will then return
* ESP_ERR_NOT_FOUND. Can be used after a coredump has been transmitted successfully.
* This function is always available, even when core dump is disabled in menuconfig.
*
* @return ESP_OK on success, otherwise \see esp_err_t
*/
esp_err_t esp_core_dump_image_erase(void);

#endif
40 changes: 37 additions & 3 deletions components/espcoredump/src/core_dump_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "esp_flash_encrypt.h"
#include "esp_rom_crc.h"

#define BLANK_COREDUMP_SIZE 0xFFFFFFFF

const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_flash";

#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH
Expand Down Expand Up @@ -389,9 +391,9 @@ esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size)
}

/* Verify that the size read from the flash is not corrupted. */
if (size == 0xFFFFFFFF) {
ESP_LOGD(TAG, "Blank core dump partition!");
err = ESP_ERR_INVALID_SIZE;
if (size == BLANK_COREDUMP_SIZE) {
ESP_LOGD(TAG, "Coredump not found, blank core dump partition!");
err = ESP_ERR_NOT_FOUND;
} else if ((size < sizeof(uint32_t)) || (size > core_part->size)) {
ESP_LOGE(TAG, "Incorrect size of core dump image: %d", size);
err = ESP_ERR_INVALID_SIZE;
Expand Down Expand Up @@ -455,3 +457,35 @@ esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size)
*out_addr = core_part->address;
return ESP_OK;
}

esp_err_t esp_core_dump_image_erase(void)
{
/* Find the partition that could potentially contain a (previous) core dump. */
const esp_partition_t *core_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
ESP_PARTITION_SUBTYPE_DATA_COREDUMP,
NULL);
if (!core_part) {
ESP_LOGE(TAG, "No core dump partition found!");
return ESP_ERR_NOT_FOUND;
}
if (core_part->size < sizeof(uint32_t)) {
ESP_LOGE(TAG, "Too small core dump partition!");
return ESP_ERR_INVALID_SIZE;
}

esp_err_t err = ESP_OK;
err = esp_partition_erase_range(core_part, 0, core_part->size);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to erase core dump partition (%d)!", err);
return err;
}

// Mark core dump as deleted by setting field size
const uint32_t blank_size = BLANK_COREDUMP_SIZE;
err = esp_partition_write(core_part, 0, &blank_size, sizeof(blank_size));
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to write core dump partition size (%d)!", err);
}

return err;
}