blob: 58a4ec3f12ad599c3dac74bd666cbe672729196c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass24b852a2015-11-08 23:47:45 -07002/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Simon Glass24b852a2015-11-08 23:47:45 -07005 */
6
7#ifndef __CONSOLE_H
8#define __CONSOLE_H
9
Simon Glass493a4c82020-07-02 21:12:13 -060010#include <stdbool.h>
Andy Shevchenko41f668b2020-12-21 14:30:00 +020011#include <stdio_dev.h>
Simon Glassbd347152020-07-28 19:41:11 -060012#include <linux/errno.h>
Simon Glass493a4c82020-07-02 21:12:13 -060013
Simon Glass24b852a2015-11-08 23:47:45 -070014extern char console_buffer[];
15
16/* common/console.c */
17int console_init_f(void); /* Before relocation; uses the serial stuff */
18int console_init_r(void); /* After relocation; uses the console stuff */
Andy Shevchenko41f668b2020-12-21 14:30:00 +020019int console_start(int file, struct stdio_dev *sdev); /* Start a console device */
20void console_stop(int file, struct stdio_dev *sdev); /* Stop a console device */
Simon Glass24b852a2015-11-08 23:47:45 -070021int console_assign(int file, const char *devname); /* Assign the console */
22int ctrlc(void);
23int had_ctrlc(void); /* have we had a Control-C since last clear? */
24void clear_ctrlc(void); /* clear the Control-C condition */
25int disable_ctrlc(int); /* 1 to disable, 0 to enable Control-C detect */
26int confirm_yesno(void); /* 1 if input is "y", "Y", "yes" or "YES" */
27
Simon Glassbd347152020-07-28 19:41:11 -060028#ifdef CONFIG_CONSOLE_RECORD
Simon Glass9854a872015-11-08 23:47:48 -070029/**
30 * console_record_init() - set up the console recording buffers
31 *
32 * This should be called as soon as malloc() is available so that the maximum
33 * amount of console output can be recorded.
Simon Glassbd347152020-07-28 19:41:11 -060034 *
35 * @return 0 if OK, -ENOMEM if out of memory
Simon Glass9854a872015-11-08 23:47:48 -070036 */
37int console_record_init(void);
38
39/**
40 * console_record_reset() - reset the console recording buffers
41 *
42 * Removes any data in the buffers
43 */
44void console_record_reset(void);
45
46/**
47 * console_record_reset_enable() - reset and enable the console buffers
48 *
49 * This should be called to enable the console buffer.
Simon Glassbd347152020-07-28 19:41:11 -060050 *
51 * @return 0 (always)
Simon Glass9854a872015-11-08 23:47:48 -070052 */
Simon Glassbd347152020-07-28 19:41:11 -060053int console_record_reset_enable(void);
Simon Glass9854a872015-11-08 23:47:48 -070054
Simon Glassb0895382017-06-15 21:37:50 -060055/**
Simon Glassb6123122020-01-27 08:49:54 -070056 * console_record_readline() - Read a line from the console output
57 *
58 * This reads the next available line from the console output previously
59 * recorded.
60 *
61 * @str: Place to put string
62 * @maxlen: Maximum length of @str including nul terminator
63 * @return length of string returned
64 */
65int console_record_readline(char *str, int maxlen);
66
67/**
68 * console_record_avail() - Get the number of available bytes in console output
69 *
70 * @return available bytes (0 if empty)
71 */
72int console_record_avail(void);
Simon Glassbd347152020-07-28 19:41:11 -060073#else
74static inline int console_record_init(void)
75{
76 /* Always succeed, since it is not enabled */
77
78 return 0;
79}
80
81static inline void console_record_reset(void)
82{
83 /* Nothing to do here */
84}
85
86static inline int console_record_reset_enable(void)
87{
88 /* Cannot enable it as it is not supported */
89 return -ENOSYS;
90}
91
92static inline int console_record_readline(char *str, int maxlen)
93{
94 /* Nothing to read */
95 return 0;
96}
97
98static inline int console_record_avail(void)
99{
100 /* There is never anything available */
101 return 0;
102}
103
104#endif /* !CONFIG_CONSOLE_RECORD */
Simon Glassb6123122020-01-27 08:49:54 -0700105
106/**
Simon Glassb0895382017-06-15 21:37:50 -0600107 * console_announce_r() - print a U-Boot console on non-serial consoles
108 *
109 * When U-Boot starts up with a display it generally does not announce itself
110 * on the display. The banner is instead emitted on the UART before relocation.
111 * This function prints a banner on devices which (we assume) did not receive
112 * it before relocation.
113 *
114 * @return 0 (meaning no errors)
115 */
116int console_announce_r(void);
117
Simon Glass493a4c82020-07-02 21:12:13 -0600118/**
119 * console_puts_select_stderr() - Output a string to selected console devices
120 *
121 * This writes to stderr only. It is useful for outputting errors
122 *
123 * @serial_only: true to output only to serial, false to output to everything
124 * else
125 * @s: String to output
126 */
127void console_puts_select_stderr(bool serial_only, const char *s);
128
Simon Glass24b852a2015-11-08 23:47:45 -0700129/*
130 * CONSOLE multiplexing.
131 */
132#ifdef CONFIG_CONSOLE_MUX
133#include <iomux.h>
134#endif
135
136#endif