mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 20:21:04 +00:00
esp32: Core dump API to retrieve current core data layout in flash
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "esp_panic.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_clk.h"
|
||||
#include "esp_core_dump.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump";
|
||||
@@ -574,5 +575,57 @@ void esp_core_dump_init()
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size)
|
||||
{
|
||||
esp_err_t err;
|
||||
const void *core_data;
|
||||
spi_flash_mmap_handle_t core_data_handle;
|
||||
|
||||
|
||||
if (out_addr == NULL || out_size == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_FAIL;
|
||||
}
|
||||
if (core_part->size < sizeof(uint32_t)) {
|
||||
ESP_LOGE(TAG, "Too small core dump partition!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
err = esp_partition_mmap(core_part, 0, sizeof(uint32_t),
|
||||
SPI_FLASH_MMAP_DATA, &core_data, &core_data_handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to mmap core dump data (%d)!", err);
|
||||
return err;
|
||||
}
|
||||
uint32_t *dw = (uint32_t *)core_data;
|
||||
*out_size = *dw;
|
||||
spi_flash_munmap(core_data_handle);
|
||||
|
||||
// remap full core dump with CRC
|
||||
err = esp_partition_mmap(core_part, 0, *out_size,
|
||||
SPI_FLASH_MMAP_DATA, &core_data, &core_data_handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to mmap core dump data (%d)!", err);
|
||||
return err;
|
||||
}
|
||||
uint32_t *crc = (uint32_t *)(((uint8_t *)core_data) + *out_size);
|
||||
crc--; // Point to CRC field
|
||||
// Calc CRC over core dump data except for CRC field
|
||||
core_dump_crc_t cur_crc = crc32_le(0, (uint8_t const *)core_data, *out_size - sizeof(core_dump_crc_t));
|
||||
if (*crc != cur_crc) {
|
||||
ESP_LOGE(TAG, "Core dump data CRC check failed: 0x%x -> 0x%x!", *crc, cur_crc);
|
||||
spi_flash_munmap(core_data_handle);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
spi_flash_munmap(core_data_handle);
|
||||
|
||||
*out_addr = core_part->address;
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user