espcoredump erase review comments

This commit is contained in:
0xFEEDC0DE64 2021-03-03 13:36:56 +01:00 committed by bot
parent a72f2e2257
commit 45de6f9c59
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
*/
esp_err_t esp_core_dump_image_erase();
esp_err_t esp_core_dump_image_erase(void);
#ifdef __cplusplus
}

View File

@ -20,6 +20,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
@ -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. */
if (size == 0xFFFFFFFF) {
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)) {
@ -460,7 +462,7 @@ esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size)
#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. */
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;
}
// on encrypted flash esp_partition_erase_range will leave encrypted
// garbage instead of 0xFFFFFFFF so overwriting again to safely signalize
// deleted coredumps
const uint32_t invalid_size = 0xFFFFFFFF;
err = esp_partition_write(core_part, 0, &invalid_size, sizeof(invalid_size));
// 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);
}