This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 02ed652b2e43a184de680c7d0187ec03805fc115 Author: wangshaoxin <[email protected]> AuthorDate: Mon Jan 20 14:07:56 2025 +0800 drivers/syslog/syslog_rpmsg: allow the driver to own its log buffer Add CONFIG_SYSLOG_RPMSG_BUFSIZE. When it is not 0, syslog_rpmsg.c defines the log buffer itself, like ramlog does, and drivers_early_initialize() calls syslog_rpmsg_init_early(NULL, 0) to use it, so a board no longer has to provide one. The buffer can be put in a section that is not initialized on boot with CONFIG_SYSLOG_RPMSG_BUFFER_SECTION, to keep the log across a reset. Signed-off-by: wangshaoxin <[email protected]> Signed-off-by: zhangyuan29 <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- drivers/drivers_initialize.c | 5 +++++ drivers/syslog/CMakeLists.txt | 6 ++++++ drivers/syslog/Kconfig | 14 ++++++++++++++ drivers/syslog/Make.defs | 4 ++++ drivers/syslog/syslog_rpmsg.c | 15 +++++++++++++++ 5 files changed, 44 insertions(+) diff --git a/drivers/drivers_initialize.c b/drivers/drivers_initialize.c index d3d5bf639e9..1bf0094e908 100644 --- a/drivers/drivers_initialize.c +++ b/drivers/drivers_initialize.c @@ -54,6 +54,7 @@ #include <nuttx/serial/uart_ram.h> #include <nuttx/syslog/syslog.h> #include <nuttx/syslog/syslog_console.h> +#include <nuttx/syslog/syslog_rpmsg.h> #include <nuttx/thermal.h> #include <nuttx/timers/ptp_clock_dummy.h> #include <nuttx/timers/ptp_pps.h> @@ -100,6 +101,10 @@ void drivers_early_initialize(void) { +#if defined(CONFIG_SYSLOG_RPMSG_BUFSIZE) && CONFIG_SYSLOG_RPMSG_BUFSIZE != 0 + syslog_rpmsg_init_early(NULL, 0); +#endif + #ifdef CONFIG_DRIVERS_NOTE note_early_initialize(); #endif diff --git a/drivers/syslog/CMakeLists.txt b/drivers/syslog/CMakeLists.txt index 9cedbaf5165..d66198d50a7 100644 --- a/drivers/syslog/CMakeLists.txt +++ b/drivers/syslog/CMakeLists.txt @@ -85,6 +85,12 @@ endif() if(CONFIG_SYSLOG_RPMSG) list(APPEND SRCS syslog_rpmsg.c) + if(NOT "${CONFIG_SYSLOG_RPMSG_BUFFER_SECTION}" STREQUAL "") + target_compile_definitions( + drivers + PRIVATE + -DSYSLOG_RPMSG_BUFFER_SECTION="${CONFIG_SYSLOG_RPMSG_BUFFER_SECTION}") + endif() endif() if(CONFIG_SYSLOG_RPMSG_SERVER) diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index ae34e1f7b9a..e48e66c3e61 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -355,6 +355,20 @@ config SYSLOG_RPMSG ---help--- Use the RPMSG as a SYSLOG output device, send message to remote proc. +config SYSLOG_RPMSG_BUFSIZE + int "RPMSG SYSLOG buffer size" + default 0 + depends on SYSLOG_RPMSG + ---help--- + Size of the console RPMSG syslog. Default: 0 + +config SYSLOG_RPMSG_BUFFER_SECTION + string "The section where rpmsg syslog buffer is located" + depends on SYSLOG_RPMSG_BUFSIZE != 0 + ---help--- + The section where rpmsg syslog buffer is located. + The section shall not be initialized on system boot. + config SYSLOG_CDCACM bool "Log to CDCACM" depends on CDCACM diff --git a/drivers/syslog/Make.defs b/drivers/syslog/Make.defs index 127f96d0eac..4420c2cff3d 100644 --- a/drivers/syslog/Make.defs +++ b/drivers/syslog/Make.defs @@ -85,6 +85,10 @@ endif ifeq ($(CONFIG_SYSLOG_RPMSG),y) CSRCS += syslog_rpmsg.c + + ifneq ($(CONFIG_SYSLOG_RPMSG_BUFFER_SECTION),"") + CFLAGS += ${DEFINE_PREFIX}SYSLOG_RPMSG_BUFFER_SECTION=CONFIG_SYSLOG_RPMSG_BUFFER_SECTION + endif endif ifeq ($(CONFIG_SYSLOG_RPMSG_SERVER),y) diff --git a/drivers/syslog/syslog_rpmsg.c b/drivers/syslog/syslog_rpmsg.c index 8a68985bf50..11162aa1d92 100644 --- a/drivers/syslog/syslog_rpmsg.c +++ b/drivers/syslog/syslog_rpmsg.c @@ -104,6 +104,15 @@ static ssize_t syslog_rpmsg_file_write(FAR struct file *filep, static struct syslog_rpmsg_s g_syslog_rpmsg; +#if CONFIG_SYSLOG_RPMSG_BUFSIZE != 0 +# ifdef SYSLOG_RPMSG_BUFFER_SECTION +static char g_sysbuffer[CONFIG_SYSLOG_RPMSG_BUFSIZE] + locate_data(CONFIG_SYSLOG_RPMSG_BUFFER_SECTION); +# else +static char g_sysbuffer[CONFIG_SYSLOG_RPMSG_BUFSIZE]; +# endif +#endif + #ifdef CONFIG_SYSLOG_RPMSG_CHARDEV static const struct file_operations g_syslog_rpmsgfops = { @@ -432,6 +441,12 @@ void syslog_rpmsg_init_early(FAR void *buffer, size_t size) char cur; size_t i; +#if CONFIG_SYSLOG_RPMSG_BUFSIZE != 0 + DEBUGASSERT(buffer == NULL && size == 0); + buffer = g_sysbuffer; + size = CONFIG_SYSLOG_RPMSG_BUFSIZE; +#endif + DEBUGASSERT((size & (size - 1)) == 0); priv->buffer = buffer;
