drivers: console: add a minimal EFI console driver to support printf
Add a minimal EFI console driver to support printf, this console driver only supports console output. Otherwise the printf will not work. Signed-off-by: Enjia Mai <enjia.mai@intel.com>
This commit is contained in:
parent
7797eb63c3
commit
89a9eab652
5 changed files with 89 additions and 1 deletions
|
@ -489,6 +489,7 @@ config X86_EFI
|
|||
config X86_EFI_CONSOLE
|
||||
bool
|
||||
depends on X86_EFI && X86_64 && !X86_VERY_EARLY_CONSOLE
|
||||
select EFI_CONSOLE
|
||||
default y
|
||||
help
|
||||
This enables the use of the UEFI console device as the
|
||||
|
|
|
@ -15,3 +15,4 @@ zephyr_library_sources_ifdef(CONFIG_UART_MCUMGR uart_mcumgr.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_UART_MUX uart_mux.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_UART_PIPE uart_pipe.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_XTENSA_SIM_CONSOLE xtensa_sim_console.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_EFI_CONSOLE efi_console.c)
|
||||
|
|
|
@ -384,5 +384,10 @@ config UART_MUX_VERBOSE_DEBUG
|
|||
As there might be lot of debug output printed, only enable
|
||||
this if really needed.
|
||||
|
||||
config EFI_CONSOLE
|
||||
bool "Use EFI console for console output"
|
||||
select CONSOLE_HAS_DRIVER
|
||||
help
|
||||
Enable this option to use EFI console output.
|
||||
|
||||
endif # CONSOLE
|
||||
|
|
82
drivers/console/efi_console.c
Normal file
82
drivers/console/efi_console.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief EFI console driver
|
||||
*
|
||||
* @details EFI console driver.
|
||||
* Hooks into the printk and fputc (for printf) modules.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
|
||||
|
||||
extern int efi_console_putchar(int c);
|
||||
|
||||
#if defined(CONFIG_PRINTK) || defined(CONFIG_STDOUT_CONSOLE)
|
||||
/**
|
||||
*
|
||||
* @brief Output one character to EFI console
|
||||
*
|
||||
* Outputs both line feed and carriage return in the case of a '\n'.
|
||||
*
|
||||
* @param c Character to output
|
||||
*
|
||||
* @return The character passed as input.
|
||||
*/
|
||||
|
||||
static int console_out(int c)
|
||||
{
|
||||
return efi_console_putchar(c);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||
extern void __stdout_hook_install(int (*hook)(int));
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PRINTK)
|
||||
extern void __printk_hook_install(int (*fn)(int));
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Install printk/stdout hook for EFI console output
|
||||
*/
|
||||
|
||||
static void efi_console_hook_install(void)
|
||||
{
|
||||
#if defined(CONFIG_STDOUT_CONSOLE)
|
||||
__stdout_hook_install(console_out);
|
||||
#endif
|
||||
#if defined(CONFIG_PRINTK)
|
||||
__printk_hook_install(console_out);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize one EFI as the console port
|
||||
*
|
||||
* @return 0 if successful, otherwise failed.
|
||||
*/
|
||||
static int efi_console_init(const struct device *arg)
|
||||
{
|
||||
|
||||
ARG_UNUSED(arg);
|
||||
|
||||
efi_console_hook_install();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EFI console initializes */
|
||||
SYS_INIT(efi_console_init,
|
||||
PRE_KERNEL_1,
|
||||
0);
|
|
@ -324,7 +324,6 @@ config INIT_STACKS
|
|||
config BOOT_BANNER
|
||||
bool "Boot banner"
|
||||
default y
|
||||
depends on CONSOLE_HAS_DRIVER
|
||||
select PRINTK
|
||||
select EARLY_CONSOLE
|
||||
help
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue