This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 4ed506d6ab01dbb1190a212368b17ebd3e47fdb1 Author: Xu Xingliang <[email protected]> AuthorDate: Wed Apr 10 12:28:20 2024 +0800 board/coredump: add option to use base64 stream Signed-off-by: Xu Xingliang <[email protected]> --- boards/Kconfig | 8 +++++++- sched/misc/coredump.c | 18 ++++++++++++++++-- tools/coredump.py | 26 +++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/boards/Kconfig b/boards/Kconfig index 4c4a32fb42..1868f5dd85 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -4666,6 +4666,13 @@ config BOARD_COREDUMP_COMPRESSION ---help--- Enable LZF compression algorithm for core dump content +config BOARD_COREDUMP_BASE64STREAM + bool "Enable base64 encoding for output stream" + default n + depends on BOARD_COREDUMP_SYSLOG + ---help--- + Enable based64 encoded stream instead of default hexstream. + config BOARD_ENTROPY_POOL bool "Enable Board level storing of entropy pool structure" default n @@ -4890,4 +4897,3 @@ config BOARD_MEMORY_RANGE end: end address of memory range flags: Readable 0x1, writable 0x2, executable 0x4 example:0x1000,0x2000,0x1,0x2000,0x3000,0x3,0x3000,0x4000,0x7 - diff --git a/sched/misc/coredump.c b/sched/misc/coredump.c index ae5e09e154..253e31d25d 100644 --- a/sched/misc/coredump.c +++ b/sched/misc/coredump.c @@ -39,7 +39,11 @@ static struct lib_lzfoutstream_s g_lzfstream; #ifdef CONFIG_BOARD_COREDUMP_SYSLOG static struct lib_syslogstream_s g_syslogstream; +# ifdef CONFIG_BOARD_COREDUMP_BASE64STREAM +static struct lib_base64outstream_s g_base64stream; +# else static struct lib_hexdumpstream_s g_hexstream; +# endif #endif #ifdef CONFIG_BOARD_COREDUMP_BLKDEV @@ -65,6 +69,7 @@ static const struct memory_region_s *g_regions; static void coredump_dump_syslog(pid_t pid) { FAR void *stream; + FAR const char *streamname; int logmask; logmask = setlogmask(LOG_ALERT); @@ -75,8 +80,16 @@ static void coredump_dump_syslog(pid_t pid) lib_syslogstream(&g_syslogstream, LOG_EMERG); stream = &g_syslogstream; +#ifdef CONFIG_BOARD_COREDUMP_BASE64STREAM + lib_base64outstream(&g_base64stream, stream); + stream = &g_base64stream; + streamname = "base64"; +#else lib_hexdumpstream(&g_hexstream, stream); stream = &g_hexstream; + streamname = "hex"; +#endif + # ifdef CONFIG_BOARD_COREDUMP_COMPRESSION /* Initialize LZF compression stream */ @@ -90,9 +103,10 @@ static void coredump_dump_syslog(pid_t pid) core_dump(g_regions, stream, pid); # ifdef CONFIG_BOARD_COREDUMP_COMPRESSION - _alert("Finish coredump (Compression Enabled).\n"); + _alert("Finish coredump (Compression Enabled). %s formatted\n", + streamname); # else - _alert("Finish coredump.\n"); + _alert("Finish coredump. %s formatted\n", streamname); # endif setlogmask(logmask); diff --git a/tools/coredump.py b/tools/coredump.py index e9d596c855..e6071442db 100755 --- a/tools/coredump.py +++ b/tools/coredump.py @@ -22,6 +22,7 @@ ############################################################################ import argparse +import base64 import binascii import os import struct @@ -69,6 +70,20 @@ def unhexlify(infile, outfile): outfile.write(binascii.unhexlify(line)) +def unbase64file(infile, outfile): + input = "" + for line in infile.readlines(): + line = line.strip() + if line == "": + break + index = line.rfind(" ") + if index > 0: + line = line[index + 1 :] + + input += line + outfile.write(base64.b64decode(input)) + + def parse_args(): global args parser = argparse.ArgumentParser( @@ -78,6 +93,12 @@ def parse_args(): ) parser.add_argument("input") parser.add_argument("-o", "--output", help="Output file in hex.") + parser.add_argument( + "--base64", + action="store_true", + default=False, + help="Set when input file is base64 encoded.", + ) args = parser.parse_args() @@ -94,7 +115,10 @@ def main(): infile = open(args.input, "r") tmpfile = open(tmp, "wb+") - unhexlify(infile, tmpfile) + if args.base64: + unbase64file(infile, tmpfile) + else: + unhexlify(infile, tmpfile) infile.close()
