Skip to content

Commit 3fa3025

Browse files
Damian-Nordicnordicjm
authored andcommitted
log_rpc: replace crash log with crash dump
Replace a custom solution for storing crash log in retained RAM and exposing it in as a string over RPC with Zephyr Core Dump module. In the latter solution RPC is only used to fetch the crash dump to the remote device. Signed-off-by: Damian Krolik <[email protected]>
1 parent 18fdaff commit 3fa3025

File tree

12 files changed

+72
-200
lines changed

12 files changed

+72
-200
lines changed

include/logging/log_rpc.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ int log_rpc_fetch_history(log_rpc_history_handler_t handler);
143143
void log_rpc_stop_fetch_history(bool pause);
144144

145145
/**
146-
* @brief Retrieves the crash log retained on the remote device.
146+
* @brief Retrieves the crash dump saved on the remote device.
147147
*
148-
* This function issues an nRF RPC command to obtain the last crash log retained
149-
* on the remote device, and then it copies the received log chunk into the
150-
* specified buffer.
148+
* This function issues an nRF RPC command to obtain a subsequent chunk of the
149+
* last crash dump saved on the remote device, and then it puts the received
150+
* chunk into the provided buffer.
151151
*
152-
* The remote may either send the entire crash log in one go, if it fits within
152+
* The remote may either send the entire dump in one go, if it fits within
153153
* the output buffer, or it may send a chunk of the log. Therefore, the caller
154154
* should repeatedly call this function, with an increasing offset, until it
155155
* returns 0 (indicating no more data), or a negative value (indicated an error).
@@ -161,7 +161,7 @@ void log_rpc_stop_fetch_history(bool pause);
161161
* @returns The number of characters copied into the output buffer.
162162
* @returns -errno Indicates failure.
163163
*/
164-
int log_rpc_get_crash_log(size_t offset, char *buffer, size_t buffer_length);
164+
int log_rpc_get_crash_dump(size_t offset, uint8_t *buffer, size_t buffer_length);
165165

166166
/**
167167
* @brief Generates a log message on the remote device.

samples/nrf_rpc/protocols_serialization/client/src/log_rpc_shell.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88

99
#include <zephyr/kernel.h>
1010
#include <zephyr/shell/shell.h>
11+
#include <zephyr/sys/util.h>
1112

1213
#include <stdlib.h>
1314

15+
#define COREDUMP_LOG_PREFIX "#CD:"
16+
#define COREDUMP_LOG_BEGIN "BEGIN#"
17+
#define COREDUMP_LOG_END "END#"
18+
#define COREDUMP_LOG_LINE_LEN 32
19+
1420
static int cmd_log_rpc_stream_level(const struct shell *sh, size_t argc, char *argv[])
1521
{
1622
int rc = 0;
@@ -143,19 +149,26 @@ static int cmd_log_rpc_crash(const struct shell *sh, size_t argc, char *argv[])
143149
{
144150
int rc;
145151
char buffer[CONFIG_RPC_CRASH_LOG_READ_BUFFER_SIZE];
152+
char line[COREDUMP_LOG_LINE_LEN * 2 + 1];
146153
size_t offset = 0;
147154

155+
shell_print(sh, COREDUMP_LOG_PREFIX COREDUMP_LOG_BEGIN);
156+
148157
while (true) {
149-
rc = log_rpc_get_crash_log(offset, buffer, sizeof(buffer));
158+
rc = log_rpc_get_crash_dump(offset, buffer, sizeof(buffer));
150159
if (rc <= 0) {
151160
break;
152161
}
153162

154-
shell_fprintf(sh, SHELL_NORMAL, "%.*s", (size_t)rc, buffer);
163+
for (int i = 0; i < rc; i += COREDUMP_LOG_LINE_LEN) {
164+
bin2hex(&buffer[i], MIN(COREDUMP_LOG_LINE_LEN, rc - i), line, sizeof(line));
165+
shell_print(sh, COREDUMP_LOG_PREFIX "%s", line);
166+
}
167+
155168
offset += (size_t)rc;
156169
}
157170

158-
shell_fprintf(sh, SHELL_NORMAL, "\n");
171+
shell_print(sh, COREDUMP_LOG_PREFIX COREDUMP_LOG_END);
159172

160173
if (rc) {
161174
shell_error(sh, "Error: %d", rc);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coredump_partition:
2+
region: flash_primary
3+
address: 0xfd000
4+
size: 0x3000
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coredump_partition:
2+
region: flash_primary
3+
address: 0x17a000
4+
size: 0x3000

samples/nrf_rpc/protocols_serialization/server/snippets/log_rpc/boards/nrf52840dk_nrf52840.overlay

Lines changed: 0 additions & 36 deletions
This file was deleted.

samples/nrf_rpc/protocols_serialization/server/snippets/log_rpc/boards/nrf54l15dk_nrf54l15_cpuapp.overlay

Lines changed: 0 additions & 35 deletions
This file was deleted.

samples/nrf_rpc/protocols_serialization/server/snippets/log_rpc/log_rpc.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ CONFIG_LOG_BACKEND_RPC_CRASH_LOG=y
1010
CONFIG_LOG_BACKEND_RPC_HISTORY=y
1111
CONFIG_LOG_BACKEND_RPC_ECHO=y
1212

13+
# Save core dump to flash partition
14+
CONFIG_DEBUG_COREDUMP=y
15+
CONFIG_DEBUG_COREDUMP_BACKEND_OTHER=y
16+
CONFIG_DEBUG_COREDUMP_BACKEND_NRF_FLASH_PARTITION=y
17+
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y
18+
CONFIG_DEBUG_COREDUMP_THREADS_METADATA=n
19+
1320
# nRF RPC requires slightly bigger stack than default
1421
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=1024
1522

samples/nrf_rpc/protocols_serialization/server/snippets/log_rpc/snippet.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,3 @@
77
name: log_rpc
88
append:
99
EXTRA_CONF_FILE: log_rpc.conf
10-
11-
boards:
12-
nrf52840dk/nrf52840:
13-
append:
14-
EXTRA_DTC_OVERLAY_FILE: boards/nrf52840dk_nrf52840.overlay
15-
nrf54l15dk/nrf54l15/cpuapp:
16-
append:
17-
EXTRA_DTC_OVERLAY_FILE: boards/nrf54l15dk_nrf54l15_cpuapp.overlay

subsys/logging/Kconfig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ endif # LOG_BACKEND_RPC_HISTORY
8888

8989
config LOG_BACKEND_RPC_CRASH_LOG
9090
bool "Crash log support"
91-
select RETENTION
92-
select RETENTION_MUTEX_FORCE_DISABLE
93-
select RETAINED_MEM
94-
select RETAINED_MEM_MUTEX_FORCE_DISABLE
91+
depends on DEBUG_COREDUMP
9592
help
9693
Enables saving the crash log in the "crash_log" retained RAM partition,
9794
and adds an nRF RPC command that allows a remote user to read the crash

0 commit comments

Comments
 (0)