summaryrefslogtreecommitdiff
path: root/common/console.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-11-08 23:47:48 -0700
committerSimon Glass <sjg@chromium.org>2015-11-19 20:27:50 -0700
commit9854a8748c8fdd69784a1fa1c4758c696621c88d (patch)
treedf09215e384695c184221ab9e3f4a295ef15efeb /common/console.c
parentb7b65090b29e6bc133c7922f8290c1e2f75b064a (diff)
downloadu-boot-imx-9854a8748c8fdd69784a1fa1c4758c696621c88d.zip
u-boot-imx-9854a8748c8fdd69784a1fa1c4758c696621c88d.tar.gz
u-boot-imx-9854a8748c8fdd69784a1fa1c4758c696621c88d.tar.bz2
console: Add a console buffer
It is useful to be able to record console output and provide console input via a buffer. This provides sandbox with the ability to run a command and check its output. If the console is set to silent then no visible output is generated. This also provides a means to fix the problem where tests produce unwanted output, such as errors or warnings. This can be confusing. We can instead set the console to silent and record this output. It can be checked later in the test if required. It is possible that this may prove useful for non-test situations. For example the console output may be suppressed for normal operations, but recorded and stored for access by the OS. That feature is not implemented at present. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/common/console.c b/common/console.c
index 10972b0..b3f126c 100644
--- a/common/console.c
+++ b/common/console.c
@@ -378,6 +378,15 @@ int getc(void)
if (!gd->have_console)
return 0;
+#ifdef CONFIG_CONSOLE_RECORD
+ if (gd->console_in.start) {
+ int ch;
+
+ ch = membuff_getbyte(&gd->console_in);
+ if (ch != -1)
+ return 1;
+ }
+#endif
if (gd->flags & GD_FLG_DEVINIT) {
/* Get from the standard input */
return fgetc(stdin);
@@ -396,7 +405,12 @@ int tstc(void)
if (!gd->have_console)
return 0;
-
+#ifdef CONFIG_CONSOLE_RECORD
+ if (gd->console_in.start) {
+ if (membuff_peekbyte(&gd->console_in) != -1)
+ return 1;
+ }
+#endif
if (gd->flags & GD_FLG_DEVINIT) {
/* Test the standard input */
return ftstc(stdin);
@@ -470,6 +484,10 @@ void putc(const char c)
return;
}
#endif
+#ifdef CONFIG_CONSOLE_RECORD
+ if (gd && (gd->flags & GD_FLG_RECORD) && gd->console_out.start)
+ membuff_putbyte(&gd->console_out, c);
+#endif
#ifdef CONFIG_SILENT_CONSOLE
if (gd->flags & GD_FLG_SILENT)
return;
@@ -513,6 +531,10 @@ void puts(const char *s)
return;
}
#endif
+#ifdef CONFIG_CONSOLE_RECORD
+ if (gd && (gd->flags & GD_FLG_RECORD) && gd->console_out.start)
+ membuff_put(&gd->console_out, s, strlen(s));
+#endif
#ifdef CONFIG_SILENT_CONSOLE
if (gd->flags & GD_FLG_SILENT)
return;
@@ -575,6 +597,32 @@ int vprintf(const char *fmt, va_list args)
return i;
}
+#ifdef CONFIG_CONSOLE_RECORD
+int console_record_init(void)
+{
+ int ret;
+
+ ret = membuff_new(&gd->console_out, CONFIG_CONSOLE_RECORD_OUT_SIZE);
+ if (ret)
+ return ret;
+ ret = membuff_new(&gd->console_in, CONFIG_CONSOLE_RECORD_IN_SIZE);
+
+ return ret;
+}
+
+void console_record_reset(void)
+{
+ membuff_purge(&gd->console_out);
+ membuff_purge(&gd->console_in);
+}
+
+void console_record_reset_enable(void)
+{
+ console_record_reset();
+ gd->flags |= GD_FLG_RECORD;
+}
+#endif
+
/* test if ctrl-c was pressed */
static int ctrlc_disabled = 0; /* see disable_ctrl() */
static int ctrlc_was_pressed = 0;