board/coredump: add option to use base64 stream

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Xu Xingliang
2024-04-10 12:28:20 +08:00
committed by Xiang Xiao
parent 64e3a1fa0b
commit 4ed506d6ab
3 changed files with 48 additions and 4 deletions
+7 -1
View File
@@ -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
+16 -2
View File
@@ -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);
+25 -1
View File
@@ -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()