Skip to content

Commit 7a6fce0

Browse files
Damian-Nordicnordicjm
authored andcommitted
logging: rpc: command to invalidate crash dump
Add log_rpc_invalidate_crash_dump() API and the underlying RPC command to invalidate crash dump stored on the remote. Signed-off-by: Damian Krolik <[email protected]>
1 parent 06262f6 commit 7a6fce0

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

include/logging/log_rpc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ void log_rpc_stop_fetch_history(bool pause);
163163
*/
164164
int log_rpc_get_crash_dump(size_t offset, uint8_t *buffer, size_t buffer_length);
165165

166+
/**
167+
* @brief Invalidates the crash dump saved on the remote device.
168+
*
169+
* This function issues an nRF RPC command to mark the crash dump saved on
170+
* the remote device as invalid, so that it can no longer be retrieved by
171+
* @ref log_rpc_get_crash_dump function.
172+
*
173+
* @returns 0 Indicates success.
174+
* @returns -errno Indicates failure.
175+
*/
176+
int log_rpc_invalidate_crash_dump(void);
177+
166178
/**
167179
* @brief Generates a log message on the remote device.
168180
*

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@ static int cmd_log_rpc_crash(const struct shell *sh, size_t argc, char *argv[])
178178
return 0;
179179
}
180180

181+
static int cmd_log_rpc_crash_invalidate(const struct shell *sh, size_t argc, char *argv[])
182+
{
183+
int rc;
184+
185+
rc = log_rpc_invalidate_crash_dump();
186+
187+
if (rc) {
188+
shell_error(sh, "Error: %d", rc);
189+
return -ENOEXEC;
190+
}
191+
192+
return 0;
193+
}
194+
181195
static int cmd_log_rpc_echo(const struct shell *sh, size_t argc, char *argv[])
182196
{
183197
int rc = 0;
@@ -216,6 +230,11 @@ static int cmd_log_rpc_time(const struct shell *sh, size_t argc, char *argv[])
216230
return 0;
217231
}
218232

233+
SHELL_STATIC_SUBCMD_SET_CREATE(crash_cmds,
234+
SHELL_CMD_ARG(invalidate, NULL, "Invalidate crash dump",
235+
cmd_log_rpc_crash_invalidate, 1, 0),
236+
SHELL_SUBCMD_SET_END);
237+
219238
SHELL_STATIC_SUBCMD_SET_CREATE(
220239
log_rpc_cmds,
221240
SHELL_CMD_ARG(stream_level, NULL, "Set log streaming level <0-4>", cmd_log_rpc_stream_level,
@@ -227,7 +246,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
227246
cmd_log_rpc_history_stop_fetch, 2, 0),
228247
SHELL_CMD_ARG(history_threshold, NULL, "Get or set history usage threshold [0-100]",
229248
cmd_log_rpc_history_threshold, 1, 1),
230-
SHELL_CMD_ARG(crash, NULL, "Retrieve remote device crash log", cmd_log_rpc_crash, 1, 0),
249+
SHELL_CMD_ARG(crash, &crash_cmds, "Retrieve crash dump from remote", cmd_log_rpc_crash, 1,
250+
0),
231251
SHELL_CMD_ARG(echo, NULL, "Generate log message on remote <0-4> <msg>", cmd_log_rpc_echo, 3,
232252
0),
233253
SHELL_CMD_ARG(time, NULL, "Set current time <time_us|now>", cmd_log_rpc_time, 2, 0),

subsys/logging/log_backend_rpc.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ static void log_rpc_get_crash_dump_handler(const struct nrf_rpc_group *group,
155155

156156
NRF_RPC_CBOR_CMD_DECODER(log_rpc_group, log_rpc_get_crash_dump_handler, LOG_RPC_CMD_GET_CRASH_DUMP,
157157
log_rpc_get_crash_dump_handler, NULL);
158+
159+
static void log_rpc_invalidate_crash_dump_handler(const struct nrf_rpc_group *group,
160+
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
161+
{
162+
int rc;
163+
164+
nrf_rpc_cbor_decoding_done(group, ctx);
165+
166+
rc = coredump_cmd(COREDUMP_CMD_INVALIDATE_STORED_DUMP, NULL);
167+
168+
nrf_rpc_rsp_send_int(group, rc);
169+
}
170+
171+
NRF_RPC_CBOR_CMD_DECODER(log_rpc_group, log_rpc_invalidate_crash_dump_handler,
172+
LOG_RPC_CMD_INVALIDATE_CRASH_DUMP, log_rpc_invalidate_crash_dump_handler,
173+
NULL);
158174
#endif /* CONFIG_LOG_BACKEND_RPC_CRASH_LOG */
159175

160176
static void format_message(struct log_msg *msg, uint32_t flags, log_output_func_t output_func,

subsys/logging/log_forwarder_rpc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ int log_rpc_get_crash_dump(size_t offset, uint8_t *buffer, size_t buffer_length)
203203
return log_chunk_size;
204204
}
205205

206+
int log_rpc_invalidate_crash_dump(void)
207+
{
208+
struct nrf_rpc_cbor_ctx ctx;
209+
int32_t rc;
210+
211+
NRF_RPC_CBOR_ALLOC(&log_rpc_group, ctx, 0);
212+
nrf_rpc_cbor_cmd_no_err(&log_rpc_group, LOG_RPC_CMD_INVALIDATE_CRASH_DUMP, &ctx,
213+
nrf_rpc_rsp_decode_i32, &rc);
214+
215+
return rc;
216+
}
217+
206218
void log_rpc_echo(enum log_rpc_level level, const char *message)
207219
{
208220
struct nrf_rpc_cbor_ctx ctx;

subsys/logging/log_rpc_group.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum log_rpc_cmd_backend {
4444
LOG_RPC_CMD_FETCH_HISTORY,
4545
LOG_RPC_CMD_STOP_FETCH_HISTORY,
4646
LOG_RPC_CMD_GET_CRASH_DUMP,
47+
LOG_RPC_CMD_INVALIDATE_CRASH_DUMP,
4748
LOG_RPC_CMD_ECHO,
4849
LOG_RPC_CMD_SET_TIME,
4950
};

0 commit comments

Comments
 (0)