Skip to content

Commit d6a32be

Browse files
noahprlubos
authored andcommitted
modules: memfault-firmware-sdk: migrate coredump from PM to devicetree
Enable support for device-tree allocated "memfault_coredump_partition" for Memfault coredump storage. Maintain support for PM-assigned partition. Partition name matches what's used in the recent memfault-firmware-sdk RRAM/MRAM backends. Add a "memfault-coredump" snippet that supplies per-board overlays for nRF52, nRF53, nRF91 DKs and Thingy:91 / Thingy:91 X, so users can enable flash-backed coredumps without writing DTS boilerplate, and instructions describing how to use the snippet or a manual overlay. Verified with: # Partition Manager (default) west build -p -b nrf9160dk/nrf9160/ns samples/debug/memfault # Devicetree (no PM) via snippet west build -p -b nrf9160dk/nrf9160/ns -S memfault-coredump \ samples/debug/memfault # Same on nRF52840 DK west build -p -b nrf52840dk/nrf52840 -S memfault-coredump \ samples/debug/memfault Note: RRAM/MRAM chips (nRF54L, nRF54H, nRF92) should use the upstream memfault-firmware-sdk backends, so this patch only covers chips that currently use the PM-managed internal flash backend. Signed-off-by: Noah Pendleton <noah.pendleton@nordicsemi.no>
1 parent 4f6d933 commit d6a32be

16 files changed

Lines changed: 708 additions & 9 deletions

doc/nrf/libraries/debug/memfault_ncs.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,37 @@ The Kconfig options for Memfault that are defined in |NCS| provide some addition
137137
* :kconfig:option:`CONFIG_MEMFAULT_NCS_STACK_METRICS`
138138
* :kconfig:option:`CONFIG_MEMFAULT_NCS_BT_METRICS`
139139

140+
.. _snippet-memfault-coredump:
141+
142+
Flash-backed coredump storage
143+
-----------------------------
144+
145+
When the :kconfig:option:`CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP` Kconfig option is enabled, the storage region is resolved at build time using one of the following sources:
146+
147+
* **Partition Manager** (legacy): When :kconfig:option:`CONFIG_PARTITION_MANAGER_ENABLED` is ``y``, a ``MEMFAULT_STORAGE`` partition is generated automatically.
148+
The size defaults to 64 kB, and you can override it with :kconfig:option:`CONFIG_PM_PARTITION_SIZE_MEMFAULT_STORAGE`.
149+
* **Devicetree** (|NCS| v3.4.0 or later recommended): When Partition Manager is disabled, the backend locates a fixed partition labeled ``memfault_coredump_partition`` under the internal flash controller.
150+
151+
The easiest way to enable the devicetree path is the :ref:`snippet-memfault-coredump` snippet that supplies a board-specific overlay defining the partition:
152+
153+
.. code-block:: console
154+
155+
west build -b <board> -S memfault-coredump <application>
156+
157+
For boards not covered by the snippet, add a node similar to the following to your application overlay:
158+
159+
.. code-block:: dts
160+
161+
&flash0 {
162+
partitions {
163+
memfault_coredump_partition: partition@fc000 {
164+
compatible = "zephyr,mapped-partition";
165+
label = "memfault_coredump_partition";
166+
reg = <0x000fc000 0x4000>;
167+
};
168+
};
169+
};
170+
140171
The |NCS| integration of `Memfault SDK`_ provides default values for some metadata that is required to identify the firmware when it is sent to Memfault cloud.
141172
You can control the defaults by using the configuration options below:
142173

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,11 @@ Edge Impulse integration
804804
Memfault integration
805805
--------------------
806806

807-
|no_changes_yet_note|
807+
* Added:
808+
809+
* Devicetree support for the internal flash coredump backend (:kconfig:option:`CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP`).
810+
The backend now locates its storage from a fixed partition labeled ``memfault_coredump_partition`` when Partition Manager is disabled, while continuing to support Partition Manager when enabled.
811+
* The :ref:`snippet-memfault-coredump` snippet that supplies a board-specific partition overlay for flash-backed coredump storage on common DKs and Thingy:91 or Thingy:91 X.
808812

809813
AVSystem integration
810814
--------------------

modules/memfault-firmware-sdk/Kconfig

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,21 +280,31 @@ config MEMFAULT_NCS_ETB_CAPTURE
280280
config MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP
281281
bool "Save coredump to internal flash instead of RAM"
282282
select MEMFAULT_COREDUMP_STORAGE_CUSTOM
283-
depends on PARTITION_MANAGER_ENABLED
284283
depends on FLASH
285284
help
286-
Use internal flash to store coredump data
285+
Use internal flash to store coredump data.
286+
287+
Storage location is resolved at build time from one of:
288+
- Partition Manager: a MEMFAULT_STORAGE partition (default size 0x10000)
289+
is generated automatically when CONFIG_PARTITION_MANAGER_ENABLED=y.
290+
- Devicetree: a fixed-partition with label "memfault_coredump_partition"
291+
under the internal flash controller. Enable the "memfault-coredump"
292+
snippet (-S memfault-coredump) or supply your own DT overlay.
287293

288294
if MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP
289295

290296
config MEMFAULT_NCS_FLASH_REGION_SIZE
291297
hex
292298
default $(dt_node_int_prop_hex,$(DT_CHOSEN_ZEPHYR_FLASH),erase-block-size)
293299

300+
if PARTITION_MANAGER_ENABLED
301+
294302
partition=MEMFAULT_STORAGE
295303
partition-size=0x10000
296304
source "$(ZEPHYR_NRF_MODULE_DIR)/subsys/partition_manager/Kconfig.template.partition_config"
297305

306+
endif # PARTITION_MANAGER_ENABLED
307+
298308
endif # MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP
299309

300310
# We want to encourage the use of a dedicated workqueue to upload data periodically,

modules/memfault-firmware-sdk/memfault_flash_coredump_storage.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@
2121
* should be used when the system is in this state.
2222
*/
2323

24+
/* Locate the coredump storage region. Two options are supported:
25+
*
26+
* 1. Partition Manager (legacy): PARTITION_*(MEMFAULT_STORAGE) macros resolve
27+
* via <pm_config.h> when CONFIG_PARTITION_MANAGER_ENABLED=y.
28+
* 2. Devicetree (NCS 3.4+): set nordic,memfault-coredump-partition in the
29+
* chosen node to point at the coredump storage partition.
30+
*/
31+
#ifdef CONFIG_PARTITION_MANAGER_ENABLED
32+
#include <pm_config.h>
33+
#define MFLT_STORAGE_OFFSET PARTITION_OFFSET(MEMFAULT_STORAGE)
34+
#define MFLT_STORAGE_SIZE PARTITION_SIZE(MEMFAULT_STORAGE)
35+
#define MFLT_STORAGE_FA_ID PARTITION_ID(MEMFAULT_STORAGE)
36+
#else
37+
#define MFLT_STORAGE_NODE DT_CHOSEN(nordic_memfault_coredump_partition)
38+
BUILD_ASSERT(DT_NODE_EXISTS(MFLT_STORAGE_NODE),
39+
"nordic,memfault-coredump-partition chosen property not set. "
40+
"Add the memfault-coredump snippet (-S memfault-coredump) or set "
41+
"nordic,memfault-coredump-partition in the chosen node of your overlay.");
42+
#define MFLT_STORAGE_OFFSET PARTITION_NODE_ADDRESS(MFLT_STORAGE_NODE)
43+
#define MFLT_STORAGE_SIZE PARTITION_NODE_SIZE(MFLT_STORAGE_NODE)
44+
#define MFLT_STORAGE_FA_ID DT_PARTITION_ID(MFLT_STORAGE_NODE)
45+
#endif
46+
2447
/* Note: While the system is running, flash writes for the nRF (soc_flash_nrf.c)
2548
* may be asynchronous so we use a static to track when a coredump clear
2649
* request has been issued.
@@ -30,7 +53,7 @@ static bool last_coredump_cleared;
3053
void memfault_platform_coredump_storage_get_info(sMfltCoredumpStorageInfo *info)
3154
{
3255
*info = (sMfltCoredumpStorageInfo) {
33-
.size = PARTITION_SIZE(MEMFAULT_STORAGE),
56+
.size = MFLT_STORAGE_SIZE,
3457
};
3558
}
3659

@@ -53,7 +76,7 @@ bool memfault_platform_coredump_storage_read(uint32_t offset, void *data, size_t
5376
}
5477

5578
/* Note: internal flash is memory mapped so we can just memcpy it out */
56-
const uint32_t address = PARTITION_OFFSET(MEMFAULT_STORAGE) + offset;
79+
const uint32_t address = MFLT_STORAGE_OFFSET + offset;
5780

5881
memcpy(data, (void *)address, read_len);
5982
return true;
@@ -75,7 +98,7 @@ bool memfault_platform_coredump_storage_erase(uint32_t offset, size_t erase_size
7598
}
7699

77100
for (size_t page = offset; page < erase_size; page += page_size) {
78-
const uint32_t address = PARTITION_OFFSET(MEMFAULT_STORAGE) + page;
101+
const uint32_t address = MFLT_STORAGE_OFFSET + page;
79102

80103
nrfx_nvmc_page_erase(address);
81104
}
@@ -88,7 +111,7 @@ bool memfault_platform_coredump_storage_erase(uint32_t offset, size_t erase_size
88111
*/
89112
bool memfault_platform_coredump_storage_buffered_write(sCoredumpWorkingBuffer *blk)
90113
{
91-
const uint32_t start_addr = PARTITION_OFFSET(MEMFAULT_STORAGE);
114+
const uint32_t start_addr = MFLT_STORAGE_OFFSET;
92115
const uint32_t addr = start_addr + blk->write_offset;
93116

94117
if (!prv_op_within_flash_bounds(blk->write_offset, MEMFAULT_COREDUMP_STORAGE_WRITE_SIZE)) {
@@ -122,7 +145,7 @@ void memfault_platform_coredump_storage_clear(void)
122145
const struct flash_area *flash_area;
123146
int err;
124147

125-
err = flash_area_open(PARTITION_ID(MEMFAULT_STORAGE), &flash_area);
148+
err = flash_area_open(MFLT_STORAGE_FA_ID, &flash_area);
126149
if (err) {
127150
MEMFAULT_LOG_ERROR("Unable to open coredump storage: 0x%x", err);
128151
return;

samples/debug/memfault/README.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,13 @@ Check and configure the following options for Memfault that are specific to |NCS
137137
* :kconfig:option:`CONFIG_MEMFAULT_NCS_STACK_METRICS`
138138
* :kconfig:option:`CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP`
139139

140-
If :kconfig:option:`CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP` is enabled, :kconfig:option:`CONFIG_PM_PARTITION_SIZE_MEMFAULT_STORAGE` can be used to set the flash partition size for the flash storage.
140+
If :kconfig:option:`CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP` is enabled, you can use :kconfig:option:`CONFIG_PM_PARTITION_SIZE_MEMFAULT_STORAGE` to set the flash partition size for the flash storage when Partition Manager is in use.
141+
142+
When building without Partition Manager (|NCS| v3.4.0 or later), enable the :ref:`snippet-memfault-coredump` snippet to supply the coredump partition using devicetree:
143+
144+
.. code-block:: console
145+
146+
west build -b <board> -S memfault-coredump samples/debug/memfault
141147
142148
.. include:: /includes/wifi_credentials_shell.txt
143149

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.. _snippet-memfault-coredump:
2+
3+
Memfault coredump snippet (memfault-coredump)
4+
#############################################
5+
6+
.. code-block:: console
7+
8+
west build -S memfault-coredump [...]
9+
10+
Overview
11+
********
12+
13+
This snippet enables flash-backed Memfault coredump storage without requiring Partition Manager.
14+
It sets the :kconfig:option:`CONFIG_MEMFAULT_NCS_INTERNAL_FLASH_BACKED_COREDUMP` Kconfig option and applies a board-specific devicetree overlay that defines a ``memfault_coredump_partition`` node within internal flash and sets the ``nordic,memfault-coredump-partition`` chosen property to point at it.
15+
16+
Supported boards
17+
****************
18+
19+
* ``nrf52840dk/nrf52840``
20+
* ``nrf5340dk/nrf5340/cpuapp`` and ``nrf5340dk/nrf5340/cpuapp/ns``
21+
* ``nrf9160dk/nrf9160/ns``
22+
* ``nrf9151dk/nrf9151/ns``
23+
* ``nrf9161dk/nrf9161/ns``
24+
* ``thingy91/nrf9160/ns``
25+
* ``thingy91x/nrf9151/ns``
26+
27+
For other boards, add a ``zephyr,mapped-partition`` node under the internal flash controller in your overlay file and set the ``nordic,memfault-coredump-partition`` chosen property to point at it, ensuring the size is aligned to a multiple of the flash erase block (typically 4 kB).
28+
29+
Notes
30+
*****
31+
32+
Set the :kconfig:option:`SB_CONFIG_PARTITION_MANAGER` Kconfig option to ``n`` (for example, using a ``Kconfig.sysbuild`` fragment in your application) to disable Partition Manager.
33+
34+
The nRF91 ``ns`` overlays redefine the full flash and modem-shared SRAM layout because disabling Partition Manager removes the TF-M and modem partition generation that the |NCS| would otherwise generate.
35+
The layouts mirror those used by the :ref:`at_client_sample` sample.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/*
8+
* Carve a 64 kB memfault coredump partition out of the application-reserved
9+
* region at the end of internal flash. The default nrf52840 layout reserves
10+
* the storage partition at 0x000f8000-0x00100000 (32 kB). Shrink it to 16 kB
11+
* and place memfault_coredump_partition immediately after.
12+
*
13+
* 0x000f8000 storage_partition (16 kB)
14+
* 0x000fc000 memfault_coredump_partition (16 kB)
15+
*
16+
* Adjust the layout to taste in your own overlay if you need different sizes.
17+
*/
18+
19+
/ {
20+
chosen {
21+
nordic,memfault-coredump-partition = &memfault_coredump_partition;
22+
};
23+
};
24+
25+
/delete-node/ &storage_partition;
26+
27+
&flash0 {
28+
partitions {
29+
storage_partition: partition@f8000 {
30+
compatible = "zephyr,mapped-partition";
31+
label = "storage";
32+
reg = <0x000f8000 0x00004000>;
33+
};
34+
35+
memfault_coredump_partition: partition@fc000 {
36+
compatible = "zephyr,mapped-partition";
37+
label = "memfault_coredump_partition";
38+
reg = <0x000fc000 0x00004000>;
39+
};
40+
};
41+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/* Shrink the default 32 kB storage partition and append a 16 kB memfault
8+
* coredump partition at the end of internal flash.
9+
*
10+
* 0x000f8000 storage_partition (16 kB)
11+
* 0x000fc000 memfault_coredump_partition (16 kB)
12+
*/
13+
14+
/ {
15+
chosen {
16+
nordic,memfault-coredump-partition = &memfault_coredump_partition;
17+
};
18+
};
19+
20+
/delete-node/ &storage_partition;
21+
22+
&flash0 {
23+
partitions {
24+
storage_partition: partition@f8000 {
25+
compatible = "zephyr,mapped-partition";
26+
label = "storage";
27+
reg = <0x000f8000 0x00004000>;
28+
};
29+
30+
memfault_coredump_partition: partition@fc000 {
31+
compatible = "zephyr,mapped-partition";
32+
label = "memfault_coredump_partition";
33+
reg = <0x000fc000 0x00004000>;
34+
};
35+
};
36+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/* See nrf5340dk_nrf5340_cpuapp.overlay for the layout rationale. */
8+
9+
/ {
10+
chosen {
11+
nordic,memfault-coredump-partition = &memfault_coredump_partition;
12+
};
13+
};
14+
15+
/delete-node/ &storage_partition;
16+
17+
&flash0 {
18+
partitions {
19+
storage_partition: partition@f8000 {
20+
compatible = "zephyr,mapped-partition";
21+
label = "storage";
22+
reg = <0x000f8000 0x00004000>;
23+
};
24+
25+
memfault_coredump_partition: partition@fc000 {
26+
compatible = "zephyr,mapped-partition";
27+
label = "memfault_coredump_partition";
28+
reg = <0x000fc000 0x00004000>;
29+
};
30+
};
31+
};

0 commit comments

Comments
 (0)