mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
refactor(espcoredump): replace uart and flash callbacks with aliases
This commit is contained in:
parent
0077c1234f
commit
4544d37078
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ESP_CORE_DUMP_BINARY_H_
|
||||
#define ESP_CORE_DUMP_BINARY_H_
|
||||
|
||||
#include "esp_core_dump_types.h"
|
||||
|
||||
/**
|
||||
* @brief Initiate the binary core dump generation.
|
||||
*
|
||||
* @param info Exception frame info generated when the panic occured.
|
||||
* @param write_cfg Structure containing the callbacks that will be called to
|
||||
* write the generated core dump file.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t.
|
||||
*/
|
||||
esp_err_t esp_core_dump_write_binary(core_dump_write_config_t *write_cfg);
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ESP_CORE_DUMP_ELF_H_
|
||||
#define ESP_CORE_DUMP_ELF_H_
|
||||
|
||||
#include "esp_core_dump_types.h"
|
||||
|
||||
/**
|
||||
* @brief Initiate the ELF core dump generation.
|
||||
*
|
||||
* @param info Exception frame info generated when the panic occured.
|
||||
* @param write_cfg Structre containing the callbacks that will be called to
|
||||
* write the generated core dump data.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t.
|
||||
*/
|
||||
esp_err_t esp_core_dump_write_elf(core_dump_write_config_t *write_cfg);
|
||||
|
||||
#endif
|
@ -96,6 +96,26 @@ bool esp_core_dump_in_isr_context(void);
|
||||
uint32_t esp_core_dump_get_user_ram_size(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function called to prepare flash/uart for the data storage
|
||||
*/
|
||||
esp_err_t esp_core_dump_write_prepare(core_dump_write_data_t *wr_data, uint32_t *data_len);
|
||||
|
||||
/**
|
||||
* @brief Function called at the beginning of data writing
|
||||
*/
|
||||
esp_err_t esp_core_dump_write_start(core_dump_write_data_t *wr_data);
|
||||
|
||||
/**
|
||||
* @brief Function called to write data chunk
|
||||
*/
|
||||
esp_err_t esp_core_dump_write_data(core_dump_write_data_t *wr_data, void *data, uint32_t data_len);
|
||||
|
||||
/**
|
||||
* @brief Function called once all data have been written
|
||||
*/
|
||||
esp_err_t esp_core_dump_write_end(core_dump_write_data_t *wr_data);
|
||||
|
||||
/**
|
||||
* @brief Get TCB length, in bytes.
|
||||
*
|
||||
|
@ -137,38 +137,6 @@ typedef struct _core_dump_write_data_t
|
||||
checksum_ctx_t checksum_ctx; /*!< Checksum context */
|
||||
} core_dump_write_data_t;
|
||||
|
||||
/**
|
||||
* @brief Types below define the signatures of the callbacks that are used
|
||||
* to output a core dump. The destination of the dump is implementation
|
||||
* dependant.
|
||||
*/
|
||||
typedef esp_err_t (*esp_core_dump_write_prepare_t)(core_dump_write_data_t* priv, uint32_t *data_len);
|
||||
typedef esp_err_t (*esp_core_dump_write_start_t)(core_dump_write_data_t* priv);
|
||||
typedef esp_err_t (*esp_core_dump_write_end_t)(core_dump_write_data_t* priv);
|
||||
typedef esp_err_t (*esp_core_dump_flash_write_data_t)(core_dump_write_data_t* priv,
|
||||
void * data,
|
||||
uint32_t data_len);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Core dump emitter control structure.
|
||||
* This structure contains the functions that are called in order to write
|
||||
* the core dump to the destination (UART or flash).
|
||||
* The function are called in this order:
|
||||
* - prepare
|
||||
* - start
|
||||
* - write (called once or more)
|
||||
* - end
|
||||
*/
|
||||
typedef struct _core_dump_write_config_t
|
||||
{
|
||||
esp_core_dump_write_prepare_t prepare; /*!< Function called for sanity checks */
|
||||
esp_core_dump_write_start_t start; /*!< Function called at the beginning of data writing */
|
||||
esp_core_dump_flash_write_data_t write; /*!< Function called to write data chunk */
|
||||
esp_core_dump_write_end_t end; /*!< Function called once all data have been written */
|
||||
core_dump_write_data_t* priv; /*!< Private context to pass to every function of this structure */
|
||||
} core_dump_write_config_t;
|
||||
|
||||
/**
|
||||
* @brief Core dump data header
|
||||
* This header predecesses the actual core dump data (ELF or binary). */
|
||||
@ -216,7 +184,7 @@ void esp_core_dump_flash_init(void);
|
||||
/**
|
||||
* @brief Common core dump write function
|
||||
*/
|
||||
void esp_core_dump_write(panic_info_t *info, core_dump_write_config_t *write_cfg);
|
||||
void esp_core_dump_write(panic_info_t *info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "core_dump_binary.h"
|
||||
#include "esp_core_dump_port.h"
|
||||
#include "esp_core_dump_common.h"
|
||||
#include "hal/efuse_hal.h"
|
||||
@ -16,9 +15,7 @@
|
||||
|
||||
const static char TAG[] __attribute__((unused)) = "esp_core_dump_binary";
|
||||
|
||||
|
||||
static esp_err_t esp_core_dump_save_task(core_dump_write_config_t *write_cfg,
|
||||
core_dump_task_header_t *task)
|
||||
static esp_err_t esp_core_dump_save_task(core_dump_write_data_t *write_data, core_dump_task_header_t *task)
|
||||
{
|
||||
esp_err_t err = ESP_FAIL;
|
||||
uint32_t stk_vaddr = 0;
|
||||
@ -28,19 +25,19 @@ static esp_err_t esp_core_dump_save_task(core_dump_write_config_t *write_cfg,
|
||||
stk_len = esp_core_dump_get_memory_len(stk_vaddr, stk_vaddr+stk_len);
|
||||
|
||||
// Save memory segment header
|
||||
err = write_cfg->write(write_cfg->priv, (void*)task, sizeof(core_dump_task_header_t));
|
||||
err = esp_core_dump_write_data(write_data, task, sizeof(core_dump_task_header_t));
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to write task header, error=%d!", err);
|
||||
return err;
|
||||
}
|
||||
// Save TCB block
|
||||
err = write_cfg->write(write_cfg->priv, task->tcb_addr, esp_core_dump_get_tcb_len());
|
||||
err = esp_core_dump_write_data(write_data, task->tcb_addr, esp_core_dump_get_tcb_len());
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to write TCB, error=%d!", err);
|
||||
return err;
|
||||
}
|
||||
// Save task stack
|
||||
err = write_cfg->write(write_cfg->priv, (void*)stk_paddr, stk_len);
|
||||
err = esp_core_dump_write_data(write_data, (void *)stk_paddr, stk_len);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to write stack for task (TCB:%x), stack_start=%x, error=%d!",
|
||||
task->tcb_addr,
|
||||
@ -49,12 +46,12 @@ static esp_err_t esp_core_dump_save_task(core_dump_write_config_t *write_cfg,
|
||||
return err;
|
||||
}
|
||||
|
||||
ESP_COREDUMP_LOG_PROCESS("Task (TCB:%x) dump is saved.",
|
||||
task->tcb_addr);
|
||||
ESP_COREDUMP_LOG_PROCESS("Task (TCB:%x) dump is saved.", task->tcb_addr);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_core_dump_save_mem_segment(core_dump_write_config_t* write_cfg,
|
||||
static esp_err_t esp_core_dump_save_mem_segment(core_dump_write_data_t* write_data,
|
||||
core_dump_mem_seg_header_t* seg)
|
||||
{
|
||||
esp_err_t err = ESP_FAIL;
|
||||
@ -64,14 +61,14 @@ static esp_err_t esp_core_dump_save_mem_segment(core_dump_write_config_t* write_
|
||||
seg->start, seg->size);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
// Save TCB address, stack base and stack top addr
|
||||
err = write_cfg->write(write_cfg->priv, (void*)seg, sizeof(core_dump_mem_seg_header_t));
|
||||
// Save TCB address, stack base and stack top addrq
|
||||
err = esp_core_dump_write_data(write_data, seg, sizeof(core_dump_mem_seg_header_t));
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to write memory segment header, error=%d!", err);
|
||||
return err;
|
||||
}
|
||||
// Save memory contents
|
||||
err = write_cfg->write(write_cfg->priv, (void*)seg->start, seg->size);
|
||||
err = esp_core_dump_write_data(write_data, (void *)seg->start, seg->size);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to write memory segment, (%x, %lu), error=%d!",
|
||||
seg->start, seg->size, err);
|
||||
@ -82,12 +79,13 @@ static esp_err_t esp_core_dump_save_mem_segment(core_dump_write_config_t* write_
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_core_dump_write_binary(core_dump_write_config_t *write_cfg)
|
||||
esp_err_t esp_core_dump_write_binary(void)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
uint32_t tcb_sz = esp_core_dump_get_tcb_len();
|
||||
uint32_t data_len = 0;
|
||||
uint32_t bad_tasks_num = 0;
|
||||
core_dump_write_data_t write_data = { 0 };
|
||||
core_dump_header_t hdr = { 0 };
|
||||
core_dump_task_header_t task_hdr = { 0 };
|
||||
core_dump_mem_seg_header_t mem_seg = { 0 };
|
||||
@ -162,21 +160,17 @@ esp_err_t esp_core_dump_write_binary(core_dump_write_config_t *write_cfg)
|
||||
ESP_COREDUMP_LOG_PROCESS("Core dump length=%lu, tasks processed: %d, broken tasks: %d",
|
||||
data_len, hdr.tasks_num, bad_tasks_num);
|
||||
// Prepare write
|
||||
if (write_cfg->prepare) {
|
||||
err = write_cfg->prepare(write_cfg->priv, &data_len);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to prepare core dump, error=%d!", err);
|
||||
return err;
|
||||
}
|
||||
err = esp_core_dump_write_prepare(&write_data, &data_len);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to prepare core dump, error=%d!", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
// Write start
|
||||
if (write_cfg->start) {
|
||||
err = write_cfg->start(write_cfg->priv);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to start core dump, error=%d!", err);
|
||||
return err;
|
||||
}
|
||||
err = esp_core_dump_write_start(&write_data);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to start core dump, error=%d!", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
// Write header
|
||||
@ -184,7 +178,7 @@ esp_err_t esp_core_dump_write_binary(core_dump_write_config_t *write_cfg)
|
||||
hdr.version = COREDUMP_VERSION_BIN_CURRENT;
|
||||
hdr.tcb_sz = tcb_sz;
|
||||
hdr.chip_rev = efuse_hal_chip_revision();
|
||||
err = write_cfg->write(write_cfg->priv, &hdr, sizeof(core_dump_header_t));
|
||||
err = esp_core_dump_write_data(&write_data, &hdr, sizeof(core_dump_header_t));
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to write core dump header error=%d!", err);
|
||||
return err;
|
||||
@ -195,7 +189,7 @@ esp_err_t esp_core_dump_write_binary(core_dump_write_config_t *write_cfg)
|
||||
// Write first crashed task data first (not always first task in the snapshot)
|
||||
ESP_COREDUMP_LOGD("Save first crashed task %x", cur_task);
|
||||
if (esp_core_dump_get_task_snapshot(cur_task, &task_hdr, NULL)) {
|
||||
err = esp_core_dump_save_task(write_cfg, &task_hdr);
|
||||
err = esp_core_dump_save_task(&write_data, &task_hdr);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to save first crashed task %x, error=%d!",
|
||||
task_hdr.tcb_addr, err);
|
||||
@ -212,8 +206,8 @@ esp_err_t esp_core_dump_write_binary(core_dump_write_config_t *write_cfg)
|
||||
continue;
|
||||
}
|
||||
ESP_COREDUMP_LOGD("Save task %x (TCB:%x, stack:%x..%x)",
|
||||
task_iter.pxTaskHandle, task_hdr.tcb_addr, task_hdr.stack_start, task_hdr.stack_end);
|
||||
err = esp_core_dump_save_task(write_cfg, &task_hdr);
|
||||
task_iter.pxTaskHandle, task_hdr.tcb_addr, task_hdr.stack_start, task_hdr.stack_end);
|
||||
err = esp_core_dump_save_task(&write_data, &task_hdr);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to save core dump task %x, error=%d!",
|
||||
task_hdr.tcb_addr, err);
|
||||
@ -230,8 +224,8 @@ esp_err_t esp_core_dump_write_binary(core_dump_write_config_t *write_cfg)
|
||||
continue;
|
||||
if (mem_seg.size > 0) {
|
||||
ESP_COREDUMP_LOG_PROCESS("Save interrupted task stack %lu bytes @ %x",
|
||||
mem_seg.size, mem_seg.start);
|
||||
err = esp_core_dump_save_mem_segment(write_cfg, &mem_seg);
|
||||
mem_seg.size, mem_seg.start);
|
||||
err = esp_core_dump_save_mem_segment(&write_data, &mem_seg);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to save interrupted task stack, error=%d!", err);
|
||||
return err;
|
||||
@ -254,8 +248,8 @@ esp_err_t esp_core_dump_write_binary(core_dump_write_config_t *write_cfg)
|
||||
mem_seg.start = start;
|
||||
mem_seg.size = esp_core_dump_get_memory_len(start, start + data_sz);;
|
||||
ESP_COREDUMP_LOG_PROCESS("Save user memory region %lu bytes @ %x",
|
||||
mem_seg.size, mem_seg.start);
|
||||
err = esp_core_dump_save_mem_segment(write_cfg, &mem_seg);
|
||||
mem_seg.size, mem_seg.start);
|
||||
err = esp_core_dump_save_mem_segment(&write_data, &mem_seg);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to save user memory region, error=%d!", err);
|
||||
return err;
|
||||
@ -265,13 +259,12 @@ esp_err_t esp_core_dump_write_binary(core_dump_write_config_t *write_cfg)
|
||||
}
|
||||
|
||||
// Write end
|
||||
if (write_cfg->end) {
|
||||
err = write_cfg->end(write_cfg->priv);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to end core dump error=%d!", err);
|
||||
return err;
|
||||
}
|
||||
err = esp_core_dump_write_end(&write_data);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to end core dump error=%d!", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (bad_tasks_num) {
|
||||
ESP_COREDUMP_LOGE("Found %d broken tasks!", bad_tasks_num);
|
||||
}
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include "esp_rom_sys.h"
|
||||
#include "esp_core_dump_port.h"
|
||||
#include "esp_core_dump_common.h"
|
||||
#include "core_dump_elf.h"
|
||||
#include "core_dump_binary.h"
|
||||
|
||||
const static char TAG[] __attribute__((unused)) = "esp_core_dump_common";
|
||||
|
||||
@ -145,7 +143,7 @@ FORCE_INLINE_ATTR void esp_core_dump_report_stack_usage(void)
|
||||
|
||||
static void* s_exc_frame = NULL;
|
||||
|
||||
inline void esp_core_dump_write(panic_info_t *info, core_dump_write_config_t *write_cfg)
|
||||
inline void esp_core_dump_write(panic_info_t *info)
|
||||
{
|
||||
#ifndef CONFIG_ESP_COREDUMP_ENABLE_TO_NONE
|
||||
esp_err_t err = ESP_ERR_NOT_SUPPORTED;
|
||||
@ -156,9 +154,11 @@ inline void esp_core_dump_write(panic_info_t *info, core_dump_write_config_t *wr
|
||||
esp_core_dump_setup_stack();
|
||||
esp_core_dump_port_init(info, isr_context);
|
||||
#if CONFIG_ESP_COREDUMP_DATA_FORMAT_BIN
|
||||
err = esp_core_dump_write_binary(write_cfg);
|
||||
esp_err_t esp_core_dump_write_binary(void);
|
||||
err = esp_core_dump_write_binary();
|
||||
#elif CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF
|
||||
err = esp_core_dump_write_elf(write_cfg);
|
||||
esp_err_t esp_core_dump_write_elf(void);
|
||||
err = esp_core_dump_write_elf();
|
||||
#endif
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Core dump write binary failed with error=%d", err);
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "esp_flash_encrypt.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "core_dump_checksum.h"
|
||||
#include "core_dump_elf.h"
|
||||
#include "esp_core_dump_port.h"
|
||||
#include "esp_core_dump_port_impl.h"
|
||||
#include "esp_core_dump_common.h"
|
||||
@ -84,7 +83,7 @@ typedef struct _core_dump_elf_t
|
||||
uint16_t elf_stage;
|
||||
uint32_t elf_next_data_offset;
|
||||
uint16_t segs_count;
|
||||
core_dump_write_config_t * write_cfg;
|
||||
core_dump_write_data_t write_data;
|
||||
uint32_t note_data_size; /* can be used where static storage needed */
|
||||
} core_dump_elf_t;
|
||||
|
||||
@ -135,7 +134,7 @@ static int elf_write_file_header(core_dump_elf_t *self, uint32_t seg_count)
|
||||
elf_hdr.e_shnum = 0; // initial section counter is 0
|
||||
elf_hdr.e_shstrndx = SHN_UNDEF; // do not use string table
|
||||
// write built elf header into elf image
|
||||
esp_err_t err = self->write_cfg->write(self->write_cfg->priv, (void*)&elf_hdr, sizeof(elf_hdr));
|
||||
esp_err_t err = esp_core_dump_write_data(&self->write_data, &elf_hdr, sizeof(elf_hdr));
|
||||
ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL,
|
||||
"Write ELF header failure (%d)", err);
|
||||
ESP_COREDUMP_LOG_PROCESS("Add file header %u bytes", sizeof(elf_hdr));
|
||||
@ -151,7 +150,7 @@ static int elf_write_segment_header(core_dump_elf_t *self, elf_phdr* phdr)
|
||||
|
||||
phdr->p_offset = self->elf_next_data_offset;
|
||||
// set segment data information and write it into image
|
||||
esp_err_t err = self->write_cfg->write(self->write_cfg->priv, (void*)phdr, sizeof(elf_phdr));
|
||||
esp_err_t err = esp_core_dump_write_data(&self->write_data, phdr, sizeof(elf_phdr));
|
||||
ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL,
|
||||
"Write ELF segment header failure (%d)", err);
|
||||
ESP_COREDUMP_LOG_PROCESS("Add segment header %u bytes: type %d, sz %u, off = 0x%x",
|
||||
@ -192,7 +191,7 @@ static int elf_add_segment(core_dump_elf_t *self,
|
||||
(uint32_t)data_len, self->elf_next_data_offset);
|
||||
// write segment data only when write function is set and phdr = NULL
|
||||
// write data into segment
|
||||
err = self->write_cfg->write(self->write_cfg->priv, data, (uint32_t)data_len);
|
||||
err = esp_core_dump_write_data(&self->write_data, data, (uint32_t)data_len);
|
||||
ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL,
|
||||
"Write ELF segment data failure (%d)", err);
|
||||
self->elf_next_data_offset += data_len;
|
||||
@ -211,11 +210,11 @@ static int elf_write_note_header(core_dump_elf_t *self,
|
||||
note_hdr.n_descsz = data_sz;
|
||||
note_hdr.n_type = type;
|
||||
// write note header
|
||||
esp_err_t err = self->write_cfg->write(self->write_cfg->priv, ¬e_hdr, sizeof(note_hdr));
|
||||
esp_err_t err = esp_core_dump_write_data(&self->write_data, ¬e_hdr, sizeof(note_hdr));
|
||||
ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL,
|
||||
"Write ELF note header failure (%d)", err);
|
||||
// write note name
|
||||
err = self->write_cfg->write(self->write_cfg->priv, name_buffer, name_len);
|
||||
err = esp_core_dump_write_data(&self->write_data, name_buffer, name_len);
|
||||
ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL,
|
||||
"Write ELF note name failure (%d)", err);
|
||||
|
||||
@ -247,13 +246,13 @@ static int elf_write_note(core_dump_elf_t *self,
|
||||
|
||||
// note data must be aligned in memory. we write aligned byte structures and panic details in strings,
|
||||
// which might not be aligned by default. Therefore, we need to verify alignment and add padding if necessary.
|
||||
err = self->write_cfg->write(self->write_cfg->priv, data, data_sz);
|
||||
err = esp_core_dump_write_data(&self->write_data, data, data_sz);
|
||||
if (err == ESP_OK) {
|
||||
int pad_size = data_len - data_sz;
|
||||
if (pad_size != 0) {
|
||||
uint8_t pad_bytes[3] = {0};
|
||||
ESP_COREDUMP_LOG_PROCESS("Core dump note data needs %d bytes padding", pad_size);
|
||||
err = self->write_cfg->write(self->write_cfg->priv, pad_bytes, pad_size);
|
||||
err = esp_core_dump_write_data(&self->write_data, pad_bytes, pad_size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -533,7 +532,7 @@ static void elf_write_core_dump_note_cb(void *opaque, const char *data)
|
||||
param->total_size += data_len;
|
||||
|
||||
if (!param->size_only) {
|
||||
esp_err_t err = self->write_cfg->write(self->write_cfg->priv, (void *)data, data_len);
|
||||
esp_err_t err = esp_core_dump_write_data(&self->write_data, (void *)data, data_len);
|
||||
if (err != ESP_OK) {
|
||||
param->total_size = 0;
|
||||
}
|
||||
@ -571,7 +570,7 @@ static int elf_add_wdt_panic_details(core_dump_elf_t *self)
|
||||
uint8_t pad_bytes[3] = {0};
|
||||
uint32_t pad_size = 4 - mod;
|
||||
ESP_COREDUMP_LOG_PROCESS("Core dump note needs %d bytes padding", pad_size);
|
||||
err = self->write_cfg->write(self->write_cfg->priv, pad_bytes, pad_size);
|
||||
err = esp_core_dump_write_data(&self->write_data, pad_bytes, pad_size);
|
||||
ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL, "Write ELF note padding failure (%d)", err);
|
||||
}
|
||||
}
|
||||
@ -670,18 +669,14 @@ static int esp_core_dump_do_write_elf_pass(core_dump_elf_t *self)
|
||||
return tot_len;
|
||||
}
|
||||
|
||||
esp_err_t esp_core_dump_write_elf(core_dump_write_config_t *write_cfg)
|
||||
esp_err_t esp_core_dump_write_elf(void)
|
||||
{
|
||||
static core_dump_elf_t self = { 0 };
|
||||
static core_dump_header_t dump_hdr = { 0 };
|
||||
core_dump_elf_t self = { 0 };
|
||||
core_dump_header_t dump_hdr = { 0 };
|
||||
esp_err_t err = ESP_OK;
|
||||
int tot_len = sizeof(dump_hdr);
|
||||
int write_len = sizeof(dump_hdr);
|
||||
|
||||
ELF_CHECK_ERR((write_cfg), ESP_ERR_INVALID_ARG, "Invalid input data.");
|
||||
|
||||
self.write_cfg = write_cfg;
|
||||
|
||||
// On first pass (do not write actual data), but calculate data length needed to allocate memory
|
||||
self.elf_stage = ELF_STAGE_CALC_SPACE;
|
||||
ESP_COREDUMP_LOG_PROCESS("================= Calc data size ===============");
|
||||
@ -692,21 +687,17 @@ esp_err_t esp_core_dump_write_elf(core_dump_write_config_t *write_cfg)
|
||||
ESP_COREDUMP_LOG_PROCESS("============== Data size = %d bytes ============", tot_len);
|
||||
|
||||
// Prepare write elf
|
||||
if (write_cfg->prepare) {
|
||||
err = write_cfg->prepare(write_cfg->priv, (uint32_t*)&tot_len);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to prepare core dump storage (%d)!", err);
|
||||
return err;
|
||||
}
|
||||
err = esp_core_dump_write_prepare(&self.write_data, (uint32_t*)&tot_len);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to prepare core dump storage (%d)!", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
// Write start
|
||||
if (write_cfg->start) {
|
||||
err = write_cfg->start(write_cfg->priv);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to start core dump (%d)!", err);
|
||||
return err;
|
||||
}
|
||||
err = esp_core_dump_write_start(&self.write_data);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to start core dump (%d)!", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
// Write core dump header
|
||||
@ -716,9 +707,7 @@ esp_err_t esp_core_dump_write_elf(core_dump_write_config_t *write_cfg)
|
||||
dump_hdr.tcb_sz = 0; // unused in ELF format
|
||||
dump_hdr.mem_segs_num = 0; // unused in ELF format
|
||||
dump_hdr.chip_rev = efuse_hal_chip_revision();
|
||||
err = write_cfg->write(write_cfg->priv,
|
||||
(void*)&dump_hdr,
|
||||
sizeof(core_dump_header_t));
|
||||
err = esp_core_dump_write_data(&self.write_data, &dump_hdr, sizeof(core_dump_header_t));
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to write core dump header (%d)!", err);
|
||||
return err;
|
||||
@ -741,13 +730,11 @@ esp_err_t esp_core_dump_write_elf(core_dump_write_config_t *write_cfg)
|
||||
ESP_COREDUMP_LOG_PROCESS("=========== Data written size = %d bytes ==========", write_len);
|
||||
|
||||
// Write end, update checksum
|
||||
if (write_cfg->end) {
|
||||
err = write_cfg->end(write_cfg->priv);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to end core dump (%d)!", err);
|
||||
return err;
|
||||
}
|
||||
err = esp_core_dump_write_end(&self.write_data);
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to end core dump (%d)!", err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,11 @@ typedef struct _core_dump_flash_config_t {
|
||||
/* Core dump flash data. */
|
||||
static core_dump_flash_config_t s_core_flash_config;
|
||||
|
||||
esp_err_t esp_core_dump_write_prepare(core_dump_write_data_t *wr_data, uint32_t *data_len) __attribute__((alias("esp_core_dump_flash_write_prepare")));
|
||||
esp_err_t esp_core_dump_write_start(core_dump_write_data_t *wr_data) __attribute__((alias("esp_core_dump_flash_write_start")));
|
||||
esp_err_t esp_core_dump_write_end(core_dump_write_data_t *wr_data) __attribute__((alias("esp_core_dump_flash_write_end")));
|
||||
esp_err_t esp_core_dump_write_data(core_dump_write_data_t *wr_data, void *data, uint32_t data_len) __attribute__((alias("esp_core_dump_flash_write_data")));
|
||||
|
||||
#define ESP_COREDUMP_FLASH_WRITE(_off_, _data_, _len_) esp_flash_write(esp_flash_default_chip, _data_, _off_, _len_)
|
||||
#define ESP_COREDUMP_FLASH_WRITE_ENCRYPTED(_off_, _data_, _len_) esp_flash_write_encrypted(esp_flash_default_chip, _off_, _data_, _len_)
|
||||
#define ESP_COREDUMP_FLASH_ERASE(_off_, _len_) esp_flash_erase_region(esp_flash_default_chip, _off_, _len_)
|
||||
@ -86,9 +91,8 @@ void esp_core_dump_flash_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
static esp_err_t esp_core_dump_flash_write_data(core_dump_write_data_t* priv, uint8_t* data, uint32_t data_size)
|
||||
static esp_err_t esp_core_dump_flash_write_data(core_dump_write_data_t* wr_data, uint8_t* data, uint32_t data_size)
|
||||
{
|
||||
core_dump_write_data_t *wr_data = (core_dump_write_data_t *)priv;
|
||||
esp_err_t err = ESP_OK;
|
||||
uint32_t written = 0;
|
||||
uint32_t wr_sz = 0;
|
||||
@ -178,9 +182,8 @@ static esp_err_t esp_core_dump_flash_write_data(core_dump_write_data_t* priv, ui
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_core_dump_flash_write_prepare(core_dump_write_data_t *priv, uint32_t *data_len)
|
||||
static esp_err_t esp_core_dump_flash_write_prepare(core_dump_write_data_t *wr_data, uint32_t *data_len)
|
||||
{
|
||||
core_dump_write_data_t *wr_data = (core_dump_write_data_t *)priv;
|
||||
esp_err_t err = ESP_OK;
|
||||
uint32_t sec_num = 0;
|
||||
uint32_t cs_len = 0;
|
||||
@ -230,19 +233,17 @@ static esp_err_t esp_core_dump_flash_write_prepare(core_dump_write_data_t *priv,
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t esp_core_dump_flash_write_start(core_dump_write_data_t* priv)
|
||||
static esp_err_t esp_core_dump_flash_write_start(core_dump_write_data_t *wr_data)
|
||||
{
|
||||
core_dump_write_data_t *wr_data = (core_dump_write_data_t *)priv;
|
||||
esp_core_dump_checksum_init(&wr_data->checksum_ctx);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_core_dump_flash_write_end(core_dump_write_data_t* priv)
|
||||
static esp_err_t esp_core_dump_flash_write_end(core_dump_write_data_t *wr_data)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
core_dump_checksum_bytes checksum = NULL;
|
||||
uint32_t cs_len = 0;
|
||||
core_dump_write_data_t *wr_data = (core_dump_write_data_t *)priv;
|
||||
|
||||
/* Get the size, in bytes of the checksum. */
|
||||
cs_len = esp_core_dump_checksum_size();
|
||||
@ -299,9 +300,6 @@ static esp_err_t esp_core_dump_flash_write_end(core_dump_write_data_t* priv)
|
||||
|
||||
void esp_core_dump_to_flash(panic_info_t *info)
|
||||
{
|
||||
core_dump_write_config_t wr_cfg = { 0 };
|
||||
core_dump_write_data_t wr_data = { 0 };
|
||||
|
||||
/* Check core dump partition configuration. */
|
||||
core_dump_crc_t crc = esp_core_dump_calc_flash_config_crc();
|
||||
if (s_core_flash_config.partition_config_crc != crc) {
|
||||
@ -319,15 +317,8 @@ void esp_core_dump_to_flash(panic_info_t *info)
|
||||
spi_flash_guard_set(&g_flash_guard_no_os_ops);
|
||||
esp_flash_app_disable_protect(true);
|
||||
|
||||
/* Register the callbacks that will be called later by the generic part. */
|
||||
wr_cfg.prepare = esp_core_dump_flash_write_prepare;
|
||||
wr_cfg.start = esp_core_dump_flash_write_start;
|
||||
wr_cfg.end = esp_core_dump_flash_write_end;
|
||||
wr_cfg.write = (esp_core_dump_flash_write_data_t) esp_core_dump_flash_write_data;
|
||||
wr_cfg.priv = &wr_data;
|
||||
|
||||
ESP_COREDUMP_LOGI("Save core dump to flash...");
|
||||
esp_core_dump_write(info, &wr_cfg);
|
||||
esp_core_dump_write(info);
|
||||
ESP_COREDUMP_LOGI("Core dump has been saved to flash.");
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,11 @@ const static char TAG[] __attribute__((unused)) = "esp_core_dump_uart";
|
||||
|
||||
#if CONFIG_ESP_COREDUMP_ENABLE_TO_UART
|
||||
|
||||
esp_err_t esp_core_dump_write_prepare(core_dump_write_data_t *wr_data, uint32_t *data_len) __attribute__((alias("esp_core_dump_uart_write_prepare")));
|
||||
esp_err_t esp_core_dump_write_start(core_dump_write_data_t *wr_data) __attribute__((alias("esp_core_dump_uart_write_start")));
|
||||
esp_err_t esp_core_dump_write_end(core_dump_write_data_t *wr_data) __attribute__((alias("esp_core_dump_uart_write_end")));
|
||||
esp_err_t esp_core_dump_write_data(core_dump_write_data_t *wr_data, void *data, uint32_t data_len) __attribute__((alias("esp_core_dump_uart_write_data")));
|
||||
|
||||
/* This function exists on every board, thus, we don't need to specify
|
||||
* explicitly the header for each board. */
|
||||
int esp_clk_cpu_freq(void);
|
||||
@ -46,30 +51,28 @@ static void esp_core_dump_b64_encode(const uint8_t *src, uint32_t src_len, uint8
|
||||
dst[j++] = '\0';
|
||||
}
|
||||
|
||||
static esp_err_t esp_core_dump_uart_write_start(core_dump_write_data_t *priv)
|
||||
static esp_err_t esp_core_dump_uart_write_start(core_dump_write_data_t *wr_data)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
core_dump_write_data_t *wr_data = (core_dump_write_data_t *)priv;
|
||||
|
||||
ESP_COREDUMP_ASSERT(priv != NULL);
|
||||
ESP_COREDUMP_ASSERT(wr_data != NULL);
|
||||
esp_core_dump_checksum_init(&wr_data->checksum_ctx);
|
||||
ESP_COREDUMP_PRINT("================= CORE DUMP START =================\r\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t esp_core_dump_uart_write_prepare(core_dump_write_data_t *priv, uint32_t *data_len)
|
||||
static esp_err_t esp_core_dump_uart_write_prepare(core_dump_write_data_t *wr_data, uint32_t *data_len)
|
||||
{
|
||||
ESP_COREDUMP_ASSERT(data_len != NULL);
|
||||
*data_len += esp_core_dump_checksum_size();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_core_dump_uart_write_end(core_dump_write_data_t *priv)
|
||||
static esp_err_t esp_core_dump_uart_write_end(core_dump_write_data_t *wr_data)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
char buf[64 + 4] = { 0 };
|
||||
core_dump_checksum_bytes cs_addr = NULL;
|
||||
core_dump_write_data_t *wr_data = (core_dump_write_data_t *)priv;
|
||||
if (wr_data) {
|
||||
size_t cs_len = esp_core_dump_checksum_finish(&wr_data->checksum_ctx, &cs_addr);
|
||||
wr_data->off += cs_len;
|
||||
@ -85,13 +88,12 @@ static esp_err_t esp_core_dump_uart_write_end(core_dump_write_data_t *priv)
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t esp_core_dump_uart_write_data(core_dump_write_data_t *priv, void * data, uint32_t data_len)
|
||||
static esp_err_t esp_core_dump_uart_write_data(core_dump_write_data_t *wr_data, void * data, uint32_t data_len)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
char buf[64 + 4] = { 0 };
|
||||
char *addr = data;
|
||||
char *end = addr + data_len;
|
||||
core_dump_write_data_t *wr_data = (core_dump_write_data_t *)priv;
|
||||
|
||||
ESP_COREDUMP_ASSERT(data != NULL);
|
||||
|
||||
@ -124,14 +126,6 @@ static int esp_core_dump_uart_get_char(void) {
|
||||
|
||||
void esp_core_dump_to_uart(panic_info_t *info)
|
||||
{
|
||||
core_dump_write_data_t wr_data = { 0 };
|
||||
core_dump_write_config_t wr_cfg = {
|
||||
.prepare = esp_core_dump_uart_write_prepare,
|
||||
.start = esp_core_dump_uart_write_start,
|
||||
.end = esp_core_dump_uart_write_end,
|
||||
.write = esp_core_dump_uart_write_data,
|
||||
.priv = (void*)&wr_data
|
||||
};
|
||||
uint32_t tm_end = 0;
|
||||
uint32_t tm_cur = 0;
|
||||
int ch = 0;
|
||||
@ -159,7 +153,7 @@ void esp_core_dump_to_uart(panic_info_t *info)
|
||||
ch = esp_core_dump_uart_get_char();
|
||||
}
|
||||
ESP_COREDUMP_LOGI("Print core dump to uart...");
|
||||
esp_core_dump_write(info, &wr_cfg);
|
||||
esp_core_dump_write(info);
|
||||
ESP_COREDUMP_LOGI("Core dump has been written to uart.");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user