[PATCH v2 2/5] console: Always define the console-recording functions

Simon Glass sjg at chromium.org
Wed Jul 29 03:41:11 CEST 2020


On boards without console recording these function are currently missing.
It is more convenient for them to be present but to return dummy values.
That way if we know that a test needs recording, we can check if it is
available, and skip the test if not, while avoiding #ifdefs.

Update the header file according and adjust console_record_reset_enable()
to return an error if recording is not available.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 common/console.c  |  4 +++-
 include/console.h | 40 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/common/console.c b/common/console.c
index 07c483f820e..8e50af1f9d2 100644
--- a/common/console.c
+++ b/common/console.c
@@ -635,10 +635,12 @@ void console_record_reset(void)
 	membuff_purge((struct membuff *)&gd->console_in);
 }
 
-void console_record_reset_enable(void)
+int console_record_reset_enable(void)
 {
 	console_record_reset();
 	gd->flags |= GD_FLG_RECORD;
+
+	return 0;
 }
 
 int console_record_readline(char *str, int maxlen)
diff --git a/include/console.h b/include/console.h
index 4c6b8f2614c..432f892b6cc 100644
--- a/include/console.h
+++ b/include/console.h
@@ -8,6 +8,7 @@
 #define __CONSOLE_H
 
 #include <stdbool.h>
+#include <linux/errno.h>
 
 extern char console_buffer[];
 
@@ -21,11 +22,14 @@ void clear_ctrlc(void);	/* clear the Control-C condition */
 int disable_ctrlc(int);	/* 1 to disable, 0 to enable Control-C detect */
 int confirm_yesno(void);        /*  1 if input is "y", "Y", "yes" or "YES" */
 
+#ifdef CONFIG_CONSOLE_RECORD
 /**
  * console_record_init() - set up the console recording buffers
  *
  * This should be called as soon as malloc() is available so that the maximum
  * amount of console output can be recorded.
+ *
+ * @return 0 if OK, -ENOMEM if out of memory
  */
 int console_record_init(void);
 
@@ -40,8 +44,10 @@ void console_record_reset(void);
  * console_record_reset_enable() - reset and enable the console buffers
  *
  * This should be called to enable the console buffer.
+ *
+ * @return 0 (always)
  */
-void console_record_reset_enable(void);
+int console_record_reset_enable(void);
 
 /**
  * console_record_readline() - Read a line from the console output
@@ -61,6 +67,38 @@ int console_record_readline(char *str, int maxlen);
  * @return available bytes (0 if empty)
  */
 int console_record_avail(void);
+#else
+static inline int console_record_init(void)
+{
+	/* Always succeed, since it is not enabled */
+
+	return 0;
+}
+
+static inline void console_record_reset(void)
+{
+	/* Nothing to do here */
+}
+
+static inline int console_record_reset_enable(void)
+{
+	/* Cannot enable it as it is not supported */
+	return -ENOSYS;
+}
+
+static inline int console_record_readline(char *str, int maxlen)
+{
+	/* Nothing to read */
+	return 0;
+}
+
+static inline int console_record_avail(void)
+{
+	/* There is never anything available */
+	return 0;
+}
+
+#endif /* !CONFIG_CONSOLE_RECORD */
 
 /**
  * console_announce_r() - print a U-Boot console on non-serial consoles
-- 
2.28.0.rc0.142.g3c755180ce-goog



More information about the U-Boot mailing list