Skip to content

Commit f526a0a

Browse files
author
Memfault Inc
committed
Memfault Firmware SDK 0.41.0 (Build 1575)
1 parent fe20bf3 commit f526a0a

File tree

17 files changed

+324
-146
lines changed

17 files changed

+324
-146
lines changed

.circleci/runas.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#
99
# ❯docker run --privileged --rm -i -t -v"$PWD":/hostdir memfault/memfault-firmware-sdk-ci /hostdir/.circleci/runas.sh
1010

11-
1211
set -euo pipefail
1312

1413
BASE_DIR=/hostdir
@@ -20,8 +19,8 @@ sudo mount -t tmpfs tmpfs /tmp/overlay
2019
mkdir /tmp/overlay/{up,work}
2120
sudo mkdir "$FINAL_DIR"
2221
sudo mount -t overlay overlay \
23-
-o lowerdir="$BASE_DIR,upperdir=/tmp/overlay/up/,workdir=/tmp/overlay/work/" \
24-
"$FINAL_DIR"
22+
-o lowerdir="$BASE_DIR,upperdir=/tmp/overlay/up/,workdir=/tmp/overlay/work/" \
23+
"$FINAL_DIR"
2524
sudo chown -R "$USER:$USER $FINAL_DIR"
2625

2726
exec bash

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### Changes between Memfault SDK 0.41.0 and SDK 0.40.0 - Feb 22, 2023
2+
3+
#### :rocket: New Features
4+
5+
- ESP-IDF:
6+
- Added coredump support for the ESP32-C3 (RISC-V) chip. Thank you to @jlubawy
7+
for your work on this in
8+
[#42](https://github.com/memfault/memfault-firmware-sdk/pull/42) 🎉!
9+
110
### Changes between Memfault SDK 0.40.1 and SDK 0.39.1 - Feb 15, 2023
211

312
#### :bomb: Breaking Changes

VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
BUILD ID: 1523
2-
GIT COMMIT: e4c98a50b
1+
BUILD ID: 1575
2+
GIT COMMIT: cacbe4d5d

cmake/Memfault.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ function(memfault_library sdk_root components src_var_name inc_var_name)
5656
list(REMOVE_ITEM SDK_SRC ${sdk_root}/components/core/src/arch_arm_cortex_m.c)
5757
list(REMOVE_ITEM SDK_SRC ${sdk_root}/components/panics/src/memfault_coredump_regions_armv7.c)
5858
list(REMOVE_ITEM SDK_SRC ${sdk_root}/components/panics/src/memfault_fault_handling_arm.c)
59+
list(REMOVE_ITEM SDK_SRC ${sdk_root}/components/panics/src/memfault_fault_handling_riscv.c)
60+
elseif(arch STREQUAL "ARCH_RISCV")
61+
list(REMOVE_ITEM SDK_SRC ${sdk_root}/components/core/src/arch_arm_cortex_m.c)
62+
list(REMOVE_ITEM SDK_SRC ${sdk_root}/components/panics/src/memfault_coredump_regions_armv7.c)
63+
list(REMOVE_ITEM SDK_SRC ${sdk_root}/components/panics/src/memfault_fault_handling_arm.c)
64+
list(REMOVE_ITEM SDK_SRC ${sdk_root}/components/panics/src/memfault_fault_handling_xtensa.c)
5965
elseif(arch STREQUAL "ARCH_ARM_CORTEX_M")
66+
list(REMOVE_ITEM SDK_SRC ${sdk_root}/components/panics/src/memfault_fault_handling_riscv.c)
6067
list(REMOVE_ITEM SDK_SRC ${sdk_root}/components/panics/src/memfault_fault_handling_xtensa.c)
6168
else()
6269
message(FATAL_ERROR "Unsupported Arch: ${arch}")
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
3+
//! @file
4+
//!
5+
//! Copyright (c) Memfault, Inc.
6+
//! See License.txt for details
7+
//!
8+
//! @brief
9+
//! RISC-V specific aspects of panic handling
10+
11+
#include <stdint.h>
12+
13+
#include "memfault/core/compiler.h"
14+
#include "memfault/core/reboot_reason_types.h"
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
//! Register State collected for RISC-V when a fault occurs
21+
MEMFAULT_PACKED_STRUCT MfltRegState {
22+
uint32_t mepc;
23+
uint32_t ra;
24+
uint32_t sp;
25+
uint32_t gp;
26+
uint32_t tp;
27+
uint32_t t[7];
28+
uint32_t s[12];
29+
uint32_t a[8];
30+
uint32_t mstatus;
31+
uint32_t mtvec;
32+
uint32_t mcause;
33+
uint32_t mtval;
34+
uint32_t mhartid;
35+
};
36+
37+
//! Called by platform assertion handlers to save info before triggering fault handling
38+
//!
39+
//! @param pc Pointer to address of assertion location
40+
//! @param lr Pointer to return address of assertion location
41+
//! @param reason Reboot reason for the assertion
42+
void memfault_arch_fault_handling_assert(void *pc, void *lr, eMemfaultRebootReason reason);
43+
44+
#ifdef __cplusplus
45+
}
46+
#endif

components/include/memfault/panics/arch/xtensa/xtensa.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef enum {
2828

2929
//! Register State collected for ESP32 when a fault occurs
3030
MEMFAULT_PACKED_STRUCT MfltRegState {
31-
uint32_t collection_type; // eMemfaultEsp32RegCollectionType
31+
uint32_t collection_type; // eMemfaultEsp32RegCollectionType
3232
// NOTE: This matches the layout expected for kMemfaultEsp32RegCollectionType_ActiveWindow
3333
uint32_t pc;
3434
uint32_t ps;
@@ -49,7 +49,7 @@ MEMFAULT_PACKED_STRUCT MfltRegState {
4949
//! @param pc Pointer to address of assertion location
5050
//! @param lr Pointer to return address of assertion location
5151
//! @param reason Reboot reason for the assertion
52-
void memfault_xtensa_fault_handling_assert(void *pc, void *lr, eMemfaultRebootReason reason);
52+
void memfault_arch_fault_handling_assert(void *pc, void *lr, eMemfaultRebootReason reason);
5353

5454
#ifdef __cplusplus
5555
}

components/include/memfault/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ typedef struct {
1919
uint8_t patch;
2020
} sMfltSdkVersion;
2121

22-
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 40, .patch = 0 }
22+
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 41, .patch = 0 }
2323

2424
#ifdef __cplusplus
2525
}

components/panics/src/memfault_coredump.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ typedef enum MfltCoredumpMachineType {
9090
kMfltCoredumpMachineType_XtensaLx106 = MEMFAULT_MACHINE_TYPE_XTENSA_LX106,
9191
kMfltCoredumpMachineType_XtensaLx7 = MEMFAULT_MACHINE_TYPE_XTENSA_LX7,
9292
kMfltCoredumpMachineType_XtensaLx7Dual = MEMFAULT_MACHINE_TYPE_XTENSA_LX7_DUAL,
93+
kMfltCoredumpMachineType_RiscV = 243,
9394
} eMfltCoredumpMachineType;
9495

9596
typedef MEMFAULT_PACKED_STRUCT MfltMachineTypeBlock {
@@ -252,6 +253,8 @@ static eMfltCoredumpMachineType prv_get_machine_type(void) {
252253
#elif defined(__XTENSA__)
253254
// finally, ESP8266
254255
kMfltCoredumpMachineType_XtensaLx106
256+
#elif defined(__riscv)
257+
kMfltCoredumpMachineType_RiscV
255258
#else
256259
#error "Coredumps are not supported for target architecture"
257260
#endif
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//! @file
2+
//!
3+
//! Copyright (c) Memfault, Inc.
4+
//! See License.txt for details
5+
//!
6+
//! Copyright (c) Memfault, Inc.
7+
//! See License.txt for details
8+
//!
9+
//! @brief
10+
//! Fault handling for RISC-V based architectures
11+
12+
#if defined(__riscv)
13+
14+
#include "memfault/core/compiler.h"
15+
#include "memfault/core/platform/core.h"
16+
#include "memfault/core/reboot_tracking.h"
17+
#include "memfault/panics/arch/riscv/riscv.h"
18+
#include "memfault/panics/coredump.h"
19+
#include "memfault/panics/coredump_impl.h"
20+
21+
const sMfltCoredumpRegion *memfault_coredump_get_arch_regions(size_t *num_regions) {
22+
*num_regions = 0;
23+
return NULL;
24+
}
25+
26+
static eMemfaultRebootReason s_crash_reason = kMfltRebootReason_Unknown;
27+
28+
static void prv_fault_handling_assert(void *pc, void *lr, eMemfaultRebootReason reason) {
29+
sMfltRebootTrackingRegInfo info = {
30+
.pc = (uint32_t)pc,
31+
.lr = (uint32_t)lr,
32+
};
33+
s_crash_reason = reason;
34+
memfault_reboot_tracking_mark_reset_imminent(s_crash_reason, &info);
35+
}
36+
37+
void memfault_arch_fault_handling_assert(void *pc, void *lr, eMemfaultRebootReason reason) {
38+
prv_fault_handling_assert(pc, lr, reason);
39+
}
40+
41+
void memfault_fault_handler(const sMfltRegState *regs, eMemfaultRebootReason reason) {
42+
if (s_crash_reason == kMfltRebootReason_Unknown) {
43+
// TODO confirm this works correctly- we should have the correct
44+
// pre-exception reg set here
45+
prv_fault_handling_assert((void *)regs->mepc, (void *)regs->ra, reason);
46+
}
47+
48+
sMemfaultCoredumpSaveInfo save_info = {
49+
.regs = regs,
50+
.regs_size = sizeof(*regs),
51+
.trace_reason = s_crash_reason,
52+
};
53+
54+
sCoredumpCrashInfo info = {
55+
.stack_address = (void *)regs->sp,
56+
.trace_reason = save_info.trace_reason,
57+
.exception_reg_state = regs,
58+
};
59+
save_info.regions = memfault_platform_coredump_get_regions(&info, &save_info.num_regions);
60+
61+
const bool coredump_saved = memfault_coredump_save(&save_info);
62+
if (coredump_saved) {
63+
memfault_reboot_tracking_mark_coredump_saved();
64+
}
65+
}
66+
67+
size_t memfault_coredump_storage_compute_size_required(void) {
68+
// actual values don't matter since we are just computing the size
69+
sMfltRegState core_regs = {0};
70+
sMemfaultCoredumpSaveInfo save_info = {
71+
.regs = &core_regs,
72+
.regs_size = sizeof(core_regs),
73+
.trace_reason = kMfltRebootReason_UnknownError,
74+
};
75+
76+
sCoredumpCrashInfo info = {
77+
// we'll just pass the current stack pointer, value shouldn't matter
78+
.stack_address = (void *)&core_regs,
79+
.trace_reason = save_info.trace_reason,
80+
.exception_reg_state = NULL,
81+
};
82+
save_info.regions = memfault_platform_coredump_get_regions(&info, &save_info.num_regions);
83+
84+
return memfault_coredump_get_save_size(&save_info);
85+
}
86+
87+
#endif // __riscv

components/panics/src/memfault_fault_handling_xtensa.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
#if defined(__XTENSA__)
1010

11-
#include "memfault/core/compiler.h"
12-
#include "memfault/core/platform/core.h"
13-
#include "memfault/core/reboot_tracking.h"
14-
#include "memfault/panics/arch/xtensa/xtensa.h"
15-
#include "memfault/panics/coredump.h"
16-
#include "memfault/panics/coredump_impl.h"
11+
#include "memfault/core/compiler.h"
12+
#include "memfault/core/platform/core.h"
13+
#include "memfault/core/reboot_tracking.h"
14+
#include "memfault/panics/arch/xtensa/xtensa.h"
15+
#include "memfault/panics/coredump.h"
16+
#include "memfault/panics/coredump_impl.h"
1717

1818
const sMfltCoredumpRegion *memfault_coredump_get_arch_regions(size_t *num_regions) {
1919
*num_regions = 0;
@@ -22,7 +22,7 @@ const sMfltCoredumpRegion *memfault_coredump_get_arch_regions(size_t *num_region
2222

2323
static eMemfaultRebootReason s_crash_reason = kMfltRebootReason_Unknown;
2424

25-
void memfault_xtensa_fault_handling_assert(void *pc, void *lr, eMemfaultRebootReason reason) {
25+
static void prv_fault_handling_assert(void *pc, void *lr, eMemfaultRebootReason reason) {
2626
sMfltRebootTrackingRegInfo info = {
2727
.pc = (uint32_t)pc,
2828
.lr = (uint32_t)lr,
@@ -31,13 +31,14 @@ void memfault_xtensa_fault_handling_assert(void *pc, void *lr, eMemfaultRebootRe
3131
memfault_reboot_tracking_mark_reset_imminent(s_crash_reason, &info);
3232
}
3333

34+
void memfault_arch_fault_handling_assert(void *pc, void *lr, eMemfaultRebootReason reason) {
35+
prv_fault_handling_assert(pc, lr, reason);
36+
}
37+
3438
void memfault_fault_handler(const sMfltRegState *regs, eMemfaultRebootReason reason) {
3539
if (s_crash_reason == kMfltRebootReason_Unknown) {
36-
sMfltRebootTrackingRegInfo info = {
37-
.pc = regs->pc,
38-
};
39-
memfault_reboot_tracking_mark_reset_imminent(reason, &info);
40-
s_crash_reason = reason;
40+
// skip LR saving here.
41+
prv_fault_handling_assert((void *)regs->pc, (void *)0, reason);
4142
}
4243

4344
sMemfaultCoredumpSaveInfo save_info = {
@@ -74,7 +75,7 @@ void memfault_fault_handler(const sMfltRegState *regs, eMemfaultRebootReason rea
7475

7576
size_t memfault_coredump_storage_compute_size_required(void) {
7677
// actual values don't matter since we are just computing the size
77-
sMfltRegState core_regs = { 0 };
78+
sMfltRegState core_regs = {0};
7879
sMemfaultCoredumpSaveInfo save_info = {
7980
.regs = &core_regs,
8081
.regs_size = sizeof(core_regs),

0 commit comments

Comments
 (0)