From 4f7c8961919bcfed90b1a9b622a31f64498a2a96 Mon Sep 17 00:00:00 2001 From: wangjianyu3 Date: Tue, 10 Mar 2026 12:58:24 +0800 Subject: [PATCH] system/nxinit: add CONFIG_SYSTEM_NXINIT_STDOUT for printf-based log output Syslog may be output via services such as DFX. When debugging the init component (e.g., service startup failures, including DFX-related exceptions), syslog may not be output properly. Add a debug Kconfig option SYSTEM_NXINIT_STDOUT that redirects all init log macros (init_debug/info/warn/err) to printf instead of syslog. This is useful for early boot debugging when syslog is not yet available or serial console shows no output. Introduce init_log_output() macro as the common log backend, selected at compile time between printf (with appended newline) and syslog. Signed-off-by: wangjianyu3 --- system/nxinit/Kconfig | 8 ++++++++ system/nxinit/init.h | 15 +++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/system/nxinit/Kconfig b/system/nxinit/Kconfig index 251ccae9bfa..a1f97561c36 100644 --- a/system/nxinit/Kconfig +++ b/system/nxinit/Kconfig @@ -168,4 +168,12 @@ config SYSTEM_NXINIT_DEBUG bool "Enable debug log" depends on SYSTEM_NXINIT_INFO +config SYSTEM_NXINIT_STDOUT + bool "Output log to stdout (printf)" + default n + ---help--- + Debug option: redirect all init logs to stdout via printf + instead of syslog. Useful when syslog is not available or + serial console has no output during early boot. + endif diff --git a/system/nxinit/init.h b/system/nxinit/init.h index e6ce868fbae..755363aeaef 100644 --- a/system/nxinit/init.h +++ b/system/nxinit/init.h @@ -28,6 +28,7 @@ ****************************************************************************/ #include +#include #include /**************************************************************************** @@ -36,8 +37,14 @@ #define TIMESPEC2MS(t) (((t).tv_sec * 1000) + (t).tv_nsec / 1000000) +#ifdef CONFIG_SYSTEM_NXINIT_STDOUT +#define init_log_output(level, fmt, ...) printf(fmt "\n", ##__VA_ARGS__) +#else +#define init_log_output(level, ...) syslog(level, ##__VA_ARGS__) +#endif + #ifdef CONFIG_SYSTEM_NXINIT_DEBUG -#define init_debug(...) syslog(LOG_USER, ##__VA_ARGS__) +#define init_debug(...) init_log_output(LOG_USER, ##__VA_ARGS__) #define init_dump_args(argc, argv) \ { \ int _i; \ @@ -52,19 +59,19 @@ #endif #ifdef CONFIG_SYSTEM_NXINIT_INFO -#define init_info(...) syslog(LOG_INFO, ##__VA_ARGS__) +#define init_info(...) init_log_output(LOG_INFO, ##__VA_ARGS__) #else #define init_info(...) #endif #ifdef CONFIG_SYSTEM_NXINIT_WARN -#define init_warn(...) syslog(LOG_WARNING, ##__VA_ARGS__) +#define init_warn(...) init_log_output(LOG_WARNING, ##__VA_ARGS__) #else #define init_warn(...) #endif #ifdef CONFIG_SYSTEM_NXINIT_ERR -#define init_err(f, ...) syslog(LOG_ERR, "Error " f, ##__VA_ARGS__) +#define init_err(f, ...) init_log_output(LOG_ERR, "Error " f, ##__VA_ARGS__) #else #define init_err(...) #endif