espcoredump erase review comments

This commit is contained in:
2021-03-03 13:36:56 +01:00
committed by bot
parent 5d4e084669
commit 418fed12df
2 changed files with 8 additions and 8 deletions

View File

@@ -96,7 +96,7 @@ esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size);
* *
* @return ESP_OK on success, otherwise \see esp_err_t * @return ESP_OK on success, otherwise \see esp_err_t
*/ */
esp_err_t esp_core_dump_image_erase(); esp_err_t esp_core_dump_image_erase(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -20,6 +20,8 @@
#include "esp_flash_encrypt.h" #include "esp_flash_encrypt.h"
#include "esp_rom_crc.h" #include "esp_rom_crc.h"
#define BLANK_COREDUMP_SIZE 0xFFFFFFFF
const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_flash"; const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_flash";
#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH #if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH
@@ -391,7 +393,7 @@ 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. */ /* Verify that the size read from the flash is not corrupted. */
if (size == 0xFFFFFFFF) { if (size == BLANK_COREDUMP_SIZE) {
ESP_LOGD(TAG, "Coredump not found, blank core dump partition!"); ESP_LOGD(TAG, "Coredump not found, blank core dump partition!");
err = ESP_ERR_NOT_FOUND; err = ESP_ERR_NOT_FOUND;
} else if ((size < sizeof(uint32_t)) || (size > core_part->size)) { } else if ((size < sizeof(uint32_t)) || (size > core_part->size)) {
@@ -460,7 +462,7 @@ esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size)
#endif #endif
esp_err_t esp_core_dump_image_erase() esp_err_t esp_core_dump_image_erase(void)
{ {
/* Find the partition that could potentially contain a (previous) core dump. */ /* 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, const esp_partition_t *core_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
@@ -482,11 +484,9 @@ esp_err_t esp_core_dump_image_erase()
return err; return err;
} }
// on encrypted flash esp_partition_erase_range will leave encrypted // Mark core dump as deleted by setting field size
// garbage instead of 0xFFFFFFFF so overwriting again to safely signalize const uint32_t blank_size = BLANK_COREDUMP_SIZE;
// deleted coredumps err = esp_partition_write(core_part, 0, &blank_size, sizeof(blank_size));
const uint32_t invalid_size = 0xFFFFFFFF;
err = esp_partition_write(core_part, 0, &invalid_size, sizeof(invalid_size));
if (err != ESP_OK) { if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to write core dump partition size (%d)!", err); ESP_LOGE(TAG, "Failed to write core dump partition size (%d)!", err);
} }