From 93537bfabdd7aaadcfe31db0ede641ec7d8050cc Mon Sep 17 00:00:00 2001 From: yukangzhi Date: Fri, 25 Apr 2025 15:47:14 +0800 Subject: [PATCH] apps/system/trace: support binary dump of noteram This patch adds support for dumping binary contents from noteram via the `trace dump -b ` command. Changes include: - Add a `binary` parameter to `trace_dump()` and the public header `system/trace/trace.h` to indicate binary output mode. - Update `trace_dump()` to set the noteram read mode to binary using `NOTERAM_SETREADMODE` when requested. - Update `trace dump` CLI parsing in `system/trace/trace.c` to accept the `-b` flag and pass it through to `trace_dump()`. - Update usage/help text to include the new `-b` option. Signed-off-by: yukangzhi --- system/trace/trace.c | 22 +++++++++++++++++----- system/trace/trace.h | 2 +- system/trace/trace_dump.c | 14 +++++++++++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/system/trace/trace.c b/system/trace/trace.c index f4a5454a40a..f414c41ea6a 100644 --- a/system/trace/trace.c +++ b/system/trace/trace.c @@ -147,10 +147,20 @@ static int trace_cmd_dump(FAR const char *name, int index, int argc, { FAR FILE *out = stdout; bool changed = false; + bool binary = false; bool cont = false; int ret; - /* Usage: trace dump [-c][] */ + /* Usage: trace dump [-b][-c][] */ + + if (index < argc) + { + if (strcmp(argv[index], "-b") == 0) + { + binary = true; + index++; + } + } if (index < argc) { @@ -192,11 +202,14 @@ static int trace_cmd_dump(FAR const char *name, int index, int argc, /* Dump the trace header */ - fputs("# tracer: nop\n#\n", out); + if (!binary) + { + fputs("# tracer: nop\n#\n", out); + } /* Dump the trace data */ - ret = trace_dump(out); + ret = trace_dump(out, binary); if (changed) { @@ -803,9 +816,8 @@ static void show_usage(void) " Get the trace while running \n" #endif #ifdef CONFIG_DRIVERS_NOTERAM - " dump [-a][-c][] :" + " dump [-b][-c][] :" " Output the trace result\n" - " [-a] \n" #endif " mode [{+|-}{o|w|s|a|i|d}...] :" " Set task trace options\n" diff --git a/system/trace/trace.h b/system/trace/trace.h index 5ac10484174..d94e3568b06 100644 --- a/system/trace/trace.h +++ b/system/trace/trace.h @@ -57,7 +57,7 @@ extern "C" * ****************************************************************************/ -int trace_dump(FAR FILE *out); +int trace_dump(FAR FILE *out, bool binary); /**************************************************************************** * Name: trace_dump_clear diff --git a/system/trace/trace_dump.c b/system/trace/trace_dump.c index d51453da125..c91b7264e93 100644 --- a/system/trace/trace_dump.c +++ b/system/trace/trace_dump.c @@ -67,7 +67,7 @@ static void note_ioctl(int cmd, unsigned long arg) * ****************************************************************************/ -int trace_dump(FAR FILE *out) +int trace_dump(FAR FILE *out, bool binary) { uint8_t tracedata[1024]; int ret; @@ -82,6 +82,18 @@ int trace_dump(FAR FILE *out) return ERROR; } + if (binary) + { + unsigned int mode = NOTERAM_MODE_READ_BINARY; + ret = ioctl(fd, NOTERAM_SETREADMODE, &mode); + if (ret < 0) + { + fprintf(stderr, "trace: cannot set read mode\n"); + close(fd); + return ERROR; + } + } + /* Read and output all notes */ while (1)