From 904ca21a00245968c26ac94dd38cb6a65fadc2b5 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Mon, 27 Jun 2022 16:45:44 +0800 Subject: [PATCH] syslog & ramlog: add BOARDIOC_RESET_CAUSE for syslog & ramlog cold boot should clear syslog & ramlog buffer Signed-off-by: Jiuzhu Dong Signed-off-by: ligd --- drivers/syslog/ramlog.c | 16 ++++++++++++++++ drivers/syslog/syslog_rpmsg.c | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c index 38c5c5392b..cf35bf9740 100644 --- a/drivers/syslog/ramlog.c +++ b/drivers/syslog/ramlog.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -224,6 +225,10 @@ static void ramlog_pollnotify(FAR struct ramlog_dev_s *priv, static void ramlog_initbuf(void) { FAR struct ramlog_dev_s *priv = &g_sysdev; +#ifdef CONFIG_BOARDCTL_RESET_CAUSE + struct boardioc_reset_cause_s cause; + int ret; +#endif bool is_empty = true; char prev; char cur; @@ -235,6 +240,17 @@ static void ramlog_initbuf(void) return; } +#ifdef CONFIG_BOARDCTL_RESET_CAUSE + memset(&cause, 0, sizeof(cause)); + ret = boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&cause); + if (ret >= 0 && cause.cause == BOARDIOC_RESETCAUSE_SYS_CHIPPOR) + { + memset(priv->rl_buffer, 0, priv->rl_bufsize); + priv->rl_head = priv->rl_tail = 0; + return; + } +#endif + prev = priv->rl_buffer[priv->rl_bufsize - 1]; for (i = 0; i < priv->rl_bufsize; i++) diff --git a/drivers/syslog/syslog_rpmsg.c b/drivers/syslog/syslog_rpmsg.c index 80bc27a2a1..9d5dbac102 100644 --- a/drivers/syslog/syslog_rpmsg.c +++ b/drivers/syslog/syslog_rpmsg.c @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef CONFIG_ARCH_LOWPUTC #include @@ -387,6 +388,10 @@ ssize_t syslog_rpmsg_write(FAR struct syslog_channel_s *channel, void syslog_rpmsg_init_early(FAR void *buffer, size_t size) { FAR struct syslog_rpmsg_s *priv = &g_syslog_rpmsg; +#ifdef CONFIG_BOARDCTL_RESET_CAUSE + struct boardioc_reset_cause_s cause; + int ret; +#endif char prev; char cur; size_t i; @@ -396,6 +401,16 @@ void syslog_rpmsg_init_early(FAR void *buffer, size_t size) priv->buffer = buffer; priv->size = size; +#ifdef CONFIG_BOARDCTL_RESET_CAUSE + memset(&cause, 0, sizeof(cause)); + ret = boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&cause); + if (ret >= 0 && cause.cause == BOARDIOC_RESETCAUSE_SYS_CHIPPOR) + { + memset(buffer, 0, size); + return; + } +#endif + prev = priv->buffer[size - 1]; for (i = 0; i < size; i++)