From b08d19bd7e92f604942fdf78b674606de7758c2e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 11 Mar 2026 11:23:00 -1000 Subject: [PATCH] Move version to first field as uint32_t Version first ensures future firmware can always identify the struct layout without depending on any other field positions. Co-Authored-By: J. Nick Koston --- esphome/components/esp32/crash_handler.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/esphome/components/esp32/crash_handler.cpp b/esphome/components/esp32/crash_handler.cpp index cabc4335206..af4dc538caf 100644 --- a/esphome/components/esp32/crash_handler.cpp +++ b/esphome/components/esp32/crash_handler.cpp @@ -28,15 +28,14 @@ static inline bool IRAM_ATTR is_code_addr(uint32_t addr) { // Raw crash data written by the panic handler wrapper. // Lives in .noinit so it survives software reset but contains garbage after power cycle. // Validated by magic marker. Static linkage since it's only used within this file. -// Field order matters: magic, version, pc, and backtrace_count are at fixed offsets -// so the struct remains readable even if MAX_BACKTRACE changes between versions. -static constexpr uint8_t CRASH_DATA_VERSION = 1; +// Version field is first so future firmware can always identify the struct layout. +// Magic is second to validate the data. Remaining fields can change between versions. +static constexpr uint32_t CRASH_DATA_VERSION = 1; struct RawCrashData { + uint32_t version; uint32_t magic; uint32_t pc; - uint8_t version; uint8_t backtrace_count; - // 2 bytes padding here, then backtrace array uint32_t backtrace[MAX_BACKTRACE]; }; static RawCrashData __attribute__((section(".noinit"))) s_raw_crash_data;