Add fix for incorrect reboot reason enum width
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c4d2434..cc04bdb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,15 @@
<!-- spellchecker:on -->
`MEMFAULT_METRICS_KEY_DEFINE_WITH_SESSION_AND_SCALE_VALUE()`
+### 🐛 Fixed
+
+- General:
+
+ - Correct an issue where `eMemfaultRebootReason` is expressed as a 4-byte type
+ instead of 2-bytes when compiling with Clang with high optimization, when
+ targeting ARM. This results in Coredumps tagged as `Unknown` instead of the
+ correct reason code.
+
## [1.14.0] - 2024-10-09
### 📈 Added
diff --git a/components/include/memfault/core/reboot_reason_types.h b/components/include/memfault/core/reboot_reason_types.h
index c0cee7b..94d89c9 100644
--- a/components/include/memfault/core/reboot_reason_types.h
+++ b/components/include/memfault/core/reboot_reason_types.h
@@ -24,7 +24,9 @@
#undef MEMFAULT_EXPECTED_REBOOT_REASON_DEFINE
#undef MEMFAULT_UNEXPECTED_REBOOT_REASON_DEFINE
-typedef enum MfltResetReason {
+//! This enum must be packed to prevent compiler optimizations in instructions which load an
+//! eMemfaultRebootReason.
+typedef enum MEMFAULT_PACKED MfltResetReason {
// A reboot reason was not determined either by hardware or a previously marked reboot reason
// This reason is classified as a crash when calculating the operational_crashfree_hours metric
kMfltRebootReason_Unknown = 0x0000,
@@ -135,6 +137,8 @@
} eMemfaultRebootReason;
+MEMFAULT_STATIC_ASSERT(sizeof(eMemfaultRebootReason) == 2, "Reboot reason enum must be 2 bytes");
+
#if MEMFAULT_REBOOT_REASON_CUSTOM_ENABLE == 1
// Ensure that the custom reboot reasons are within the expected range
#define MEMFAULT_EXPECTED_REBOOT_REASON_DEFINE(name) \