Skip to content

Commit

Permalink
feat(espcoredump): Include boot time and unix time in header
Browse files Browse the repository at this point in the history
  • Loading branch information
nebkat committed May 9, 2024
1 parent d4cd437 commit 523d526
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ extern "C" {
(((_maj_)&0xFF) << 8) | \
(((_min_)&0xFF) << 0) \
)
#define COREDUMP_VERSION_BIN 0
#define COREDUMP_VERSION_ELF 1
#define COREDUMP_VERSION_BIN 1
#define COREDUMP_VERSION_ELF 2

/* legacy bin coredumps (before IDF v4.1) has version set to 1 */
#define COREDUMP_VERSION_BIN_LEGACY COREDUMP_VERSION_MAKE(COREDUMP_VERSION_BIN, 1) // -> 0x0001
Expand Down Expand Up @@ -146,6 +146,8 @@ typedef struct _core_dump_header_t {
uint32_t tcb_sz; /*!< Size of a TCB, in bytes */
uint32_t mem_segs_num; /*!< Number of memory segments */
uint32_t chip_rev; /*!< Chip revision */
uint64_t boot_time; /*!< Boot time, in microseconds */
uint64_t unix_time; /*!< Unix time, in microseconds */
} core_dump_header_t;

/**
Expand Down
5 changes: 5 additions & 0 deletions components/espcoredump/src/core_dump_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ static esp_err_t esp_core_dump_write_binary(void)
hdr.version = COREDUMP_VERSION_BIN_CURRENT;
hdr.tcb_sz = tcb_sz;
hdr.chip_rev = efuse_hal_chip_revision();
dump_hdr.boot_time = esp_timer_get_time();

struct timeval tv;
gettimeofday(&tv, NULL);
dump_hdr.unix_time = tv.tv_sec * 1000000 + tv.tv_usec;
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);
Expand Down
7 changes: 7 additions & 0 deletions components/espcoredump/src/core_dump_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#ifdef CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF
#include <sys/param.h> // for the MIN macro
#include <sys/time.h>
#include "esp_app_desc.h"
#endif

Expand Down Expand Up @@ -852,6 +853,12 @@ static esp_err_t esp_core_dump_write_elf(void)
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();
dump_hdr.boot_time = esp_timer_get_time();

struct timeval tv;
gettimeofday(&tv, NULL);
dump_hdr.unix_time = tv.tv_sec * 1000000 + tv.tv_usec;

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);
Expand Down

0 comments on commit 523d526

Please sign in to comment.