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

espcoredump: Support for not overwriting existing core dump in flash (IDFGH-10907) #12105

Closed
wants to merge 1 commit 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
10 changes: 10 additions & 0 deletions components/espcoredump/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ menu "Core dump"
Config delay (in ms) before printing core dump to UART.
Delay can be interrupted by pressing Enter key.

config ESP_COREDUMP_FLASH_NO_OVERWRITE
bool "Don't overwrite existing core dump"
depends on ESP_COREDUMP_ENABLE_TO_FLASH
default n
help
Don't overwrite an existing core dump already present in flash.
Enable this option to only keep the first of multiple core dumps.

If enabled, the core dump partition must be erased before the first
core dump can be written.

config ESP_COREDUMP_USE_STACK_SIZE
bool
Expand Down
30 changes: 30 additions & 0 deletions components/espcoredump/src/core_dump_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ typedef struct _core_dump_partition_t
uint32_t size;
/* Flag set to true if the partition is encrypted. */
bool encrypted;
#if CONFIG_ESP_COREDUMP_FLASH_NO_OVERWRITE
/* Flag set to true if the partition is empty. */
bool empty;
#endif
} core_dump_partition_t;

typedef uint32_t core_dump_crc_t;
Expand Down Expand Up @@ -82,6 +86,18 @@ void esp_core_dump_flash_init(void)
s_core_flash_config.partition.start = core_part->address;
s_core_flash_config.partition.size = core_part->size;
s_core_flash_config.partition.encrypted = core_part->encrypted;

#if CONFIG_ESP_COREDUMP_FLASH_NO_OVERWRITE
uint32_t core_size = 0;
esp_err_t err = esp_partition_read(core_part, 0, &core_size, sizeof(core_size));
if (err == ESP_OK) {
s_core_flash_config.partition.empty = (core_size == BLANK_COREDUMP_SIZE);
} else {
ESP_COREDUMP_LOGE("Failed to read core dump data size (%d)!", err);
s_core_flash_config.partition.empty = false;
}
#endif

s_core_flash_config.partition_config_crc = esp_core_dump_calc_flash_config_crc();

if (esp_flash_encryption_enabled() && !core_part->encrypted) {
Expand Down Expand Up @@ -318,6 +334,13 @@ void esp_core_dump_to_flash(panic_info_t *info)
return;
}

#if CONFIG_ESP_COREDUMP_FLASH_NO_OVERWRITE
if (!s_core_flash_config.partition.empty) {
ESP_COREDUMP_LOGW("Core dump already exists in flash, will not overwrite it with a new core dump");
return;
}
#endif

/* Initialize non-OS flash access critical section. */
spi_flash_guard_set(&g_flash_guard_no_os_ops);
esp_flash_app_disable_protect(true);
Expand Down Expand Up @@ -457,6 +480,13 @@ esp_err_t esp_core_dump_image_erase(void)
ESP_LOGE(TAG, "Failed to write core dump partition size (%d)!", err);
}

#if CONFIG_ESP_COREDUMP_FLASH_NO_OVERWRITE
if (!s_core_flash_config.partition.empty) {
s_core_flash_config.partition.empty = true;
s_core_flash_config.partition_config_crc = esp_core_dump_calc_flash_config_crc();
}
#endif

return err;
}

Expand Down
Loading