lib: os: add a header for printk hook functions
Add a zephyr/printk.h header for the __printk_hook functions, these are currently manually declared by all console drivers for no good reason. Move the documentation into the header and also unify the way that console drivers call the function. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
parent
84cddc6ab3
commit
ef14c9b867
15 changed files with 59 additions and 80 deletions
|
@ -16,7 +16,7 @@
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
|
|
||||||
extern int efi_console_putchar(int c);
|
extern int efi_console_putchar(int c);
|
||||||
|
|
||||||
|
@ -43,10 +43,6 @@ static int console_out(int c)
|
||||||
extern void __stdout_hook_install(int (*hook)(int));
|
extern void __stdout_hook_install(int (*hook)(int));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_PRINTK)
|
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Install printk/stdout hook for EFI console output
|
* @brief Install printk/stdout hook for EFI console output
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/drivers/ipm.h>
|
#include <zephyr/drivers/ipm.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
|
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
LOG_MODULE_REGISTER(ipm_console, CONFIG_IPM_LOG_LEVEL);
|
LOG_MODULE_REGISTER(ipm_console, CONFIG_IPM_LOG_LEVEL);
|
||||||
|
@ -43,25 +44,17 @@ static int console_out(int c)
|
||||||
|
|
||||||
#if defined(CONFIG_STDOUT_CONSOLE)
|
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||||
extern void __stdout_hook_install(int (*hook)(int));
|
extern void __stdout_hook_install(int (*hook)(int));
|
||||||
#else
|
|
||||||
#define __stdout_hook_install(x) \
|
|
||||||
do { /* nothing */ \
|
|
||||||
} while ((0))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_PRINTK)
|
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
#else
|
|
||||||
#define __printk_hook_install(x) \
|
|
||||||
do { /* nothing */ \
|
|
||||||
} while ((0))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Install printk/stdout hooks */
|
/* Install printk/stdout hooks */
|
||||||
static void ipm_console_hook_install(void)
|
static void ipm_console_hook_install(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||||
__stdout_hook_install(console_out);
|
__stdout_hook_install(console_out);
|
||||||
|
#endif
|
||||||
|
#if defined(CONFIG_PRINTK)
|
||||||
__printk_hook_install(console_out);
|
__printk_hook_install(console_out);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ipm_console_init(void)
|
static int ipm_console_init(void)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
#include <zephyr/drivers/ipm.h>
|
#include <zephyr/drivers/ipm.h>
|
||||||
#include <zephyr/drivers/console/ipm_console.h>
|
#include <zephyr/drivers/console/ipm_console.h>
|
||||||
|
|
||||||
|
@ -30,7 +31,6 @@ static int consoleOut(int character)
|
||||||
return character;
|
return character;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
extern void __stdout_hook_install(int (*fn)(int));
|
extern void __stdout_hook_install(int (*fn)(int));
|
||||||
|
|
||||||
int ipm_console_sender_init(const struct device *d)
|
int ipm_console_sender_init(const struct device *d)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
|
|
||||||
|
@ -27,18 +28,6 @@ static int console_out(int c)
|
||||||
|
|
||||||
#if defined(CONFIG_STDOUT_CONSOLE)
|
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||||
extern void __stdout_hook_install(int (*hook)(int));
|
extern void __stdout_hook_install(int (*hook)(int));
|
||||||
#else
|
|
||||||
#define __stdout_hook_install(x) \
|
|
||||||
do {/* nothing */ \
|
|
||||||
} while ((0))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_PRINTK)
|
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
#else
|
|
||||||
#define __printk_hook_install(x) \
|
|
||||||
do {/* nothing */ \
|
|
||||||
} while ((0))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,8 +36,12 @@ extern void __printk_hook_install(int (*fn)(int));
|
||||||
*/
|
*/
|
||||||
static int jailhouse_console_init(void)
|
static int jailhouse_console_init(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||||
__stdout_hook_install(console_out);
|
__stdout_hook_install(console_out);
|
||||||
|
#endif
|
||||||
|
#if defined(CONFIG_PRINTK)
|
||||||
__printk_hook_install(console_out);
|
__printk_hook_install(console_out);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/arch/posix/posix_trace.h>
|
#include <zephyr/arch/posix/posix_trace.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
|
|
||||||
#define _STDOUT_BUF_SIZE 256
|
#define _STDOUT_BUF_SIZE 256
|
||||||
static char stdout_buff[_STDOUT_BUF_SIZE];
|
static char stdout_buff[_STDOUT_BUF_SIZE];
|
||||||
|
@ -51,7 +52,6 @@ void posix_flush_stdout(void)
|
||||||
static int posix_arch_console_init(void)
|
static int posix_arch_console_init(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_PRINTK
|
#ifdef CONFIG_PRINTK
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
__printk_hook_install(print_char);
|
__printk_hook_install(print_char);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_STDOUT_CONSOLE
|
#ifdef CONFIG_STDOUT_CONSOLE
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/linker/devicetree_regions.h>
|
#include <zephyr/linker/devicetree_regions.h>
|
||||||
|
@ -27,7 +28,6 @@
|
||||||
#define RAM_CONSOLE_BUF_ATTR
|
#define RAM_CONSOLE_BUF_ATTR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
extern void __stdout_hook_install(int (*fn)(int));
|
extern void __stdout_hook_install(int (*fn)(int));
|
||||||
|
|
||||||
char ram_console_buf[CONFIG_RAM_CONSOLE_BUFFER_SIZE] RAM_CONSOLE_BUF_ATTR;
|
char ram_console_buf[CONFIG_RAM_CONSOLE_BUFFER_SIZE] RAM_CONSOLE_BUF_ATTR;
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
|
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <SEGGER_RTT.h>
|
#include <SEGGER_RTT.h>
|
||||||
|
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
extern void __stdout_hook_install(int (*fn)(int));
|
extern void __stdout_hook_install(int (*fn)(int));
|
||||||
|
|
||||||
static bool host_present;
|
static bool host_present;
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <zephyr/linker/sections.h>
|
#include <zephyr/linker/sections.h>
|
||||||
#include <zephyr/sys/atomic.h>
|
#include <zephyr/sys/atomic.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
#include <zephyr/pm/device_runtime.h>
|
#include <zephyr/pm/device_runtime.h>
|
||||||
#ifdef CONFIG_UART_CONSOLE_MCUMGR
|
#ifdef CONFIG_UART_CONSOLE_MCUMGR
|
||||||
#include <zephyr/mgmt/mcumgr/transport/serial.h>
|
#include <zephyr/mgmt/mcumgr/transport/serial.h>
|
||||||
|
@ -114,10 +115,6 @@ static int console_out(int c)
|
||||||
extern void __stdout_hook_install(int (*hook)(int c));
|
extern void __stdout_hook_install(int (*hook)(int c));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_PRINTK)
|
|
||||||
extern void __printk_hook_install(int (*fn)(int c));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_CONSOLE_HANDLER)
|
#if defined(CONFIG_CONSOLE_HANDLER)
|
||||||
static struct k_fifo *avail_queue;
|
static struct k_fifo *avail_queue;
|
||||||
static struct k_fifo *lines_queue;
|
static struct k_fifo *lines_queue;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/sys/winstream.h>
|
#include <zephyr/sys/winstream.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
#include <zephyr/devicetree.h>
|
#include <zephyr/devicetree.h>
|
||||||
#include <zephyr/cache.h>
|
#include <zephyr/cache.h>
|
||||||
|
|
||||||
|
@ -48,24 +49,16 @@ int arch_printk_char_out(int c)
|
||||||
|
|
||||||
#if defined(CONFIG_STDOUT_CONSOLE)
|
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||||
extern void __stdout_hook_install(int (*hook)(int));
|
extern void __stdout_hook_install(int (*hook)(int));
|
||||||
#else
|
|
||||||
#define __stdout_hook_install(x) \
|
|
||||||
do {/* nothing */ \
|
|
||||||
} while ((0))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_PRINTK)
|
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
#else
|
|
||||||
#define __printk_hook_install(x) \
|
|
||||||
do {/* nothing */ \
|
|
||||||
} while ((0))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void winstream_console_hook_install(void)
|
static void winstream_console_hook_install(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||||
__stdout_hook_install(arch_printk_char_out);
|
__stdout_hook_install(arch_printk_char_out);
|
||||||
|
#endif
|
||||||
|
#if defined(CONFIG_PRINTK)
|
||||||
__printk_hook_install(arch_printk_char_out);
|
__printk_hook_install(arch_printk_char_out);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <xtensa/simcall.h>
|
#include <xtensa/simcall.h>
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
|
|
||||||
#if defined(CONFIG_PRINTK) || defined(CONFIG_STDOUT_CONSOLE)
|
#if defined(CONFIG_PRINTK) || defined(CONFIG_STDOUT_CONSOLE)
|
||||||
/**
|
/**
|
||||||
|
@ -35,18 +36,6 @@ int arch_printk_char_out(int c)
|
||||||
|
|
||||||
#if defined(CONFIG_STDOUT_CONSOLE)
|
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||||
extern void __stdout_hook_install(int (*hook)(int));
|
extern void __stdout_hook_install(int (*hook)(int));
|
||||||
#else
|
|
||||||
#define __stdout_hook_install(x) \
|
|
||||||
do {/* nothing */ \
|
|
||||||
} while ((0))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_PRINTK)
|
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
#else
|
|
||||||
#define __printk_hook_install(x) \
|
|
||||||
do {/* nothing */ \
|
|
||||||
} while ((0))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,8 +43,12 @@ extern void __printk_hook_install(int (*fn)(int));
|
||||||
*/
|
*/
|
||||||
static void xt_sim_console_hook_install(void)
|
static void xt_sim_console_hook_install(void)
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||||
__stdout_hook_install(arch_printk_char_out);
|
__stdout_hook_install(arch_printk_char_out);
|
||||||
|
#endif
|
||||||
|
#if defined(CONFIG_PRINTK)
|
||||||
__printk_hook_install(arch_printk_char_out);
|
__printk_hook_install(arch_printk_char_out);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/sys/device_mmio.h>
|
#include <zephyr/sys/device_mmio.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
|
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
LOG_MODULE_REGISTER(uart_hvc_xen, CONFIG_UART_LOG_LEVEL);
|
LOG_MODULE_REGISTER(uart_hvc_xen, CONFIG_UART_LOG_LEVEL);
|
||||||
|
@ -267,7 +268,6 @@ DEVICE_DT_DEFINE(DT_NODELABEL(xen_hvc), xen_console_init, NULL, &xen_hvc_data,
|
||||||
&xen_hvc_api);
|
&xen_hvc_api);
|
||||||
|
|
||||||
#ifdef CONFIG_XEN_EARLY_CONSOLEIO
|
#ifdef CONFIG_XEN_EARLY_CONSOLEIO
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
extern void __stdout_hook_install(int (*fn)(int));
|
extern void __stdout_hook_install(int (*fn)(int));
|
||||||
|
|
||||||
int xen_consoleio_putc(int c)
|
int xen_consoleio_putc(int c)
|
||||||
|
|
29
include/zephyr/sys/printk-hooks.h
Normal file
29
include/zephyr/sys/printk-hooks.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2024 Google LLC
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZEPHYR_INCLUDE_SYS_PRINTK_HOOKS_H_
|
||||||
|
#define ZEPHYR_INCLUDE_SYS_PRINTK_HOOKS_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Install the character output routine for printk
|
||||||
|
*
|
||||||
|
* To be called by the platform's console driver at init time. Installs a
|
||||||
|
* routine that outputs one ASCII character at a time.
|
||||||
|
* @param fn putc routine to install
|
||||||
|
*/
|
||||||
|
void __printk_hook_install(int (*fn)(int c));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the current character output routine for printk
|
||||||
|
*
|
||||||
|
* To be called by any console driver that would like to save
|
||||||
|
* current hook - if any - for later re-installation.
|
||||||
|
*
|
||||||
|
* @return a function pointer or NULL if no hook is set
|
||||||
|
*/
|
||||||
|
void *__printk_get_hook(void);
|
||||||
|
|
||||||
|
#endif /* ZEPHYR_INCLUDE_SYS_PRINTK_HOOKS_H_ */
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <zephyr/toolchain.h>
|
#include <zephyr/toolchain.h>
|
||||||
#include <zephyr/linker/sections.h>
|
#include <zephyr/linker/sections.h>
|
||||||
|
@ -54,26 +55,11 @@ __attribute__((weak)) int arch_printk_char_out(int c)
|
||||||
|
|
||||||
static int (*_char_out)(int c) = arch_printk_char_out;
|
static int (*_char_out)(int c) = arch_printk_char_out;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Install the character output routine for printk
|
|
||||||
*
|
|
||||||
* To be called by the platform's console driver at init time. Installs a
|
|
||||||
* routine that outputs one ASCII character at a time.
|
|
||||||
* @param fn putc routine to install
|
|
||||||
*/
|
|
||||||
void __printk_hook_install(int (*fn)(int c))
|
void __printk_hook_install(int (*fn)(int c))
|
||||||
{
|
{
|
||||||
_char_out = fn;
|
_char_out = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the current character output routine for printk
|
|
||||||
*
|
|
||||||
* To be called by any console driver that would like to save
|
|
||||||
* current hook - if any - for later re-installation.
|
|
||||||
*
|
|
||||||
* @return a function pointer or NULL if no hook is set
|
|
||||||
*/
|
|
||||||
void *__printk_get_hook(void)
|
void *__printk_get_hook(void)
|
||||||
{
|
{
|
||||||
return _char_out;
|
return _char_out;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/drivers/uart_pipe.h>
|
#include <zephyr/drivers/uart_pipe.h>
|
||||||
#include <zephyr/sys/byteorder.h>
|
#include <zephyr/sys/byteorder.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
#include <zephyr/drivers/uart.h>
|
#include <zephyr/drivers/uart.h>
|
||||||
|
|
||||||
#include <zephyr/logging/log_backend.h>
|
#include <zephyr/logging/log_backend.h>
|
||||||
|
@ -260,7 +261,6 @@ static int monitor_console_out(int c)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void __printk_hook_install(int (*fn)(int));
|
|
||||||
extern void __stdout_hook_install(int (*fn)(int));
|
extern void __stdout_hook_install(int (*fn)(int));
|
||||||
#endif /* !CONFIG_UART_CONSOLE && !CONFIG_RTT_CONSOLE && !CONFIG_LOG_PRINTK */
|
#endif /* !CONFIG_UART_CONSOLE && !CONFIG_RTT_CONSOLE && !CONFIG_LOG_PRINTK */
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <zephyr/ztest.h>
|
#include <zephyr/ztest.h>
|
||||||
|
#include <zephyr/sys/printk-hooks.h>
|
||||||
|
|
||||||
#define BUF_SZ 1024
|
#define BUF_SZ 1024
|
||||||
|
|
||||||
static int pos;
|
static int pos;
|
||||||
char pk_console[BUF_SZ];
|
char pk_console[BUF_SZ];
|
||||||
|
|
||||||
void __printk_hook_install(int (*fn)(int));
|
|
||||||
void *__printk_get_hook(void);
|
|
||||||
int (*_old_char_out)(int);
|
int (*_old_char_out)(int);
|
||||||
|
|
||||||
#if defined(CONFIG_PICOLIBC)
|
#if defined(CONFIG_PICOLIBC)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue