* [PATCH v3 0/4] console: remove #ifdef CONFIG when it is possible
@ 2020-12-18 11:46 Patrick Delaunay
2020-12-18 11:46 ` [PATCH v3 1/4] " Patrick Delaunay
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Patrick Delaunay @ 2020-12-18 11:46 UTC (permalink / raw)
To: u-boot
Hi,
It is the V3 of serie [1] after Simon Glass comments.
Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible
This patchset can applied on master branch after the serie [2]
(for the new order of test in function putc() and puts()
done in "console: allow to record console output before ready"
)
For information:
I try to remove the sandox code in [3] (with the associated tests
#ifdef CONFIG_SANDBOX) but it wasn't a correct idea.
I will pushed a separate serie to remove the remaining
#ifdef CONFIG_VIDCONSOLE_AS_LCD [4]
[1] http://patchwork.ozlabs.org/project/uboot/list/?series=218309
[2] http://patchwork.ozlabs.org/project/uboot/list/?series=217079
"log: don't build the trace buffer when log is not ready"
[3] http://patchwork.ozlabs.org/project/uboot/patch/20201127114927.2.Ida70f4fb1524187703e9240d63e436f8ae5adaab at changeid/
"[2/2] console: sandbox: remove unnecessary sandbox code"
[4] http://patchwork.ozlabs.org/project/uboot/list/?series=218307
"video: remove VIDCONSOLE_AS_LCD and VIDCONSOLE_AS_NAME"
Changes in v3:
- update commit message with new function name console_has_tstc
Changes in v2:
- update also #ifdef CONFIG_SANDBOX after Simon Glass remark
(code can't be removed to avoid to rely sandbox on debug uart)
- move the tests on gd->flags & GD_FLG_RECORD in helper functions
- remove test on IS_ENABLED(CONFIG_CONSOLE_RECORD)
before to call helper functions
- add comment for tstcdev variable
- rename console_tstc_check to console_has_tstc
Patrick Delaunay (4):
console: remove #ifdef CONFIG when it is possible
console: add function console_devices_set
console: remove #ifdef CONFIG_CONSOLE_RECORD
console: add console_has_tstc helper function for CONSOLE_MUX
common/console.c | 310 ++++++++++++++++++++++++++---------------------
1 file changed, 175 insertions(+), 135 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 1/4] console: remove #ifdef CONFIG when it is possible
2020-12-18 11:46 [PATCH v3 0/4] console: remove #ifdef CONFIG when it is possible Patrick Delaunay
@ 2020-12-18 11:46 ` Patrick Delaunay
2020-12-19 3:34 ` Simon Glass
2021-01-16 16:24 ` Tom Rini
2020-12-18 11:46 ` [PATCH v3 2/4] console: add function console_devices_set Patrick Delaunay
` (2 subsequent siblings)
3 siblings, 2 replies; 13+ messages in thread
From: Patrick Delaunay @ 2020-12-18 11:46 UTC (permalink / raw)
To: u-boot
From: Patrick Delaunay <patrick.delaunay@st.com>
Remove #ifdef or #ifndef for CONFIG when it is possible to simplify
the console.c code and respect the U-Boot coding rules.
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
(no changes since v2)
Changes in v2:
- update also #ifdef CONFIG_SANDBOX after Simon Glass remark
(code can't be removed to avoid to rely sandbox on debug uart)
common/console.c | 158 +++++++++++++++++++----------------------------
1 file changed, 64 insertions(+), 94 deletions(-)
diff --git a/common/console.c b/common/console.c
index c3d552bb3e..d225fdd920 100644
--- a/common/console.c
+++ b/common/console.c
@@ -44,14 +44,15 @@ static int on_console(const char *name, const char *value, enum env_op op,
case env_op_create:
case env_op_overwrite:
-#if CONFIG_IS_ENABLED(CONSOLE_MUX)
- if (iomux_doenv(console, value))
- return 1;
-#else
- /* Try assigning specified device */
- if (console_assign(console, value) < 0)
- return 1;
-#endif
+ if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
+ if (iomux_doenv(console, value))
+ return 1;
+ } else {
+ /* Try assigning specified device */
+ if (console_assign(console, value) < 0)
+ return 1;
+ }
+
return 0;
case env_op_delete:
@@ -69,14 +70,13 @@ U_BOOT_ENV_CALLBACK(console, on_console);
static int on_silent(const char *name, const char *value, enum env_op op,
int flags)
{
-#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET)
- if (flags & H_INTERACTIVE)
- return 0;
-#endif
-#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC)
- if ((flags & H_INTERACTIVE) == 0)
- return 0;
-#endif
+ if (!CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET))
+ if (flags & H_INTERACTIVE)
+ return 0;
+
+ if (!CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC))
+ if ((flags & H_INTERACTIVE) == 0)
+ return 0;
if (value != NULL)
gd->flags |= GD_FLG_SILENT;
@@ -159,14 +159,13 @@ static bool console_dev_is_serial(struct stdio_dev *sdev)
{
bool is_serial;
-#ifdef CONFIG_DM_SERIAL
- if (sdev->flags & DEV_FLAGS_DM) {
+ if (IS_ENABLED(CONFIG_DM_SERIAL) && (sdev->flags & DEV_FLAGS_DM)) {
struct udevice *dev = sdev->priv;
is_serial = device_get_uclass_id(dev) == UCLASS_SERIAL;
- } else
-#endif
- is_serial = !strcmp(sdev->name, "serial");
+ } else {
+ is_serial = !strcmp(sdev->name, "serial");
+ }
return is_serial;
}
@@ -350,13 +349,12 @@ int fgetc(int file)
if (console_tstc(file))
return console_getc(file);
#endif
-#ifdef CONFIG_WATCHDOG
/*
* If the watchdog must be rate-limited then it should
* already be handled in board-specific code.
*/
- udelay(1);
-#endif
+ if (IS_ENABLED(CONFIG_WATCHDOG))
+ udelay(1);
}
}
@@ -406,10 +404,8 @@ int fprintf(int file, const char *fmt, ...)
int getchar(void)
{
-#ifdef CONFIG_DISABLE_CONSOLE
- if (gd->flags & GD_FLG_DISABLE_CONSOLE)
+ if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
return 0;
-#endif
if (!gd->have_console)
return 0;
@@ -434,10 +430,8 @@ int getchar(void)
int tstc(void)
{
-#ifdef CONFIG_DISABLE_CONSOLE
- if (gd->flags & GD_FLG_DISABLE_CONSOLE)
+ if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
return 0;
-#endif
if (!gd->have_console)
return 0;
@@ -485,10 +479,8 @@ static void print_pre_console_buffer(int flushpoint)
char buf_out[CONFIG_PRE_CON_BUF_SZ + 1];
char *buf_in;
-#ifdef CONFIG_SILENT_CONSOLE
- if (gd->flags & GD_FLG_SILENT)
+ if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT))
return;
-#endif
buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ);
if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ)
@@ -523,32 +515,26 @@ void putc(const char c)
if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
membuff_putbyte((struct membuff *)&gd->console_out, c);
#endif
-#ifdef CONFIG_SANDBOX
/* sandbox can send characters to stdout before it has a console */
- if (!(gd->flags & GD_FLG_SERIAL_READY)) {
+ if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) {
os_putc(c);
return;
}
-#endif
-#ifdef CONFIG_DEBUG_UART
+
/* if we don't have a console yet, use the debug UART */
- if (!(gd->flags & GD_FLG_SERIAL_READY)) {
+ if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY)) {
printch(c);
return;
}
-#endif
-#ifdef CONFIG_SILENT_CONSOLE
- if (gd->flags & GD_FLG_SILENT) {
+
+ if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) {
if (!(gd->flags & GD_FLG_DEVINIT))
pre_console_putc(c);
return;
}
-#endif
-#ifdef CONFIG_DISABLE_CONSOLE
- if (gd->flags & GD_FLG_DISABLE_CONSOLE)
+ if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
return;
-#endif
if (!gd->have_console)
return pre_console_putc(c);
@@ -571,15 +557,13 @@ void puts(const char *s)
if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
membuff_put((struct membuff *)&gd->console_out, s, strlen(s));
#endif
-#ifdef CONFIG_SANDBOX
/* sandbox can send characters to stdout before it has a console */
- if (!(gd->flags & GD_FLG_SERIAL_READY)) {
+ if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) {
os_puts(s);
return;
}
-#endif
-#ifdef CONFIG_DEBUG_UART
- if (!(gd->flags & GD_FLG_SERIAL_READY)) {
+
+ if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY)) {
while (*s) {
int ch = *s++;
@@ -587,19 +571,15 @@ void puts(const char *s)
}
return;
}
-#endif
-#ifdef CONFIG_SILENT_CONSOLE
- if (gd->flags & GD_FLG_SILENT) {
+
+ if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) {
if (!(gd->flags & GD_FLG_DEVINIT))
pre_console_puts(s);
return;
}
-#endif
-#ifdef CONFIG_DISABLE_CONSOLE
- if (gd->flags & GD_FLG_DISABLE_CONSOLE)
+ if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
return;
-#endif
if (!gd->have_console)
return pre_console_puts(s);
@@ -772,19 +752,19 @@ int console_assign(int file, const char *devname)
/* return true if the 'silent' flag is removed */
static bool console_update_silent(void)
{
-#ifdef CONFIG_SILENT_CONSOLE
- if (env_get("silent")) {
- gd->flags |= GD_FLG_SILENT;
- } else {
- unsigned long flags = gd->flags;
+ unsigned long flags = gd->flags;
- gd->flags &= ~GD_FLG_SILENT;
+ if (!IS_ENABLED(CONFIG_SILENT_CONSOLE))
+ return false;
- return !!(flags & GD_FLG_SILENT);
+ if (env_get("silent")) {
+ gd->flags |= GD_FLG_SILENT;
+ return false;
}
-#endif
- return false;
+ gd->flags &= ~GD_FLG_SILENT;
+
+ return !!(flags & GD_FLG_SILENT);
}
int console_announce_r(void)
@@ -843,12 +823,8 @@ int console_init_r(void)
{
char *stdinname, *stdoutname, *stderrname;
struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
-#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
int i;
-#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
-#if CONFIG_IS_ENABLED(CONSOLE_MUX)
int iomux_err = 0;
-#endif
int flushpoint;
/* update silent for env loaded from flash (initr_env) */
@@ -874,14 +850,14 @@ int console_init_r(void)
inputdev = search_device(DEV_FLAGS_INPUT, stdinname);
outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname);
errdev = search_device(DEV_FLAGS_OUTPUT, stderrname);
-#if CONFIG_IS_ENABLED(CONSOLE_MUX)
- iomux_err = iomux_doenv(stdin, stdinname);
- iomux_err += iomux_doenv(stdout, stdoutname);
- iomux_err += iomux_doenv(stderr, stderrname);
- if (!iomux_err)
- /* Successful, so skip all the code below. */
- goto done;
-#endif
+ if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
+ iomux_err = iomux_doenv(stdin, stdinname);
+ iomux_err += iomux_doenv(stdout, stdoutname);
+ iomux_err += iomux_doenv(stderr, stderrname);
+ if (!iomux_err)
+ /* Successful, so skip all the code below. */
+ goto done;
+ }
}
/* if the devices are overwritten or not found, use default device */
if (inputdev == NULL) {
@@ -907,25 +883,22 @@ int console_init_r(void)
console_doenv(stdin, inputdev);
}
-#if CONFIG_IS_ENABLED(CONSOLE_MUX)
done:
-#endif
-#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
- stdio_print_current_devices();
-#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
+ if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET))
+ stdio_print_current_devices();
+
#ifdef CONFIG_VIDCONSOLE_AS_LCD
if (strstr(stdoutname, CONFIG_VIDCONSOLE_AS_NAME))
printf("Warning: Please change '%s' to 'vidconsole' in stdout/stderr environment vars\n",
CONFIG_VIDCONSOLE_AS_NAME);
#endif
-#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
- /* set the environment variables (will overwrite previous env settings) */
- for (i = 0; i < MAX_FILES; i++) {
- env_set(stdio_names[i], stdio_devices[i]->name);
+ if (IS_ENABLED(CONFIG_SYS_CONSOLE_ENV_OVERWRITE)) {
+ /* set the environment variables (will overwrite previous env settings) */
+ for (i = 0; i < MAX_FILES; i++)
+ env_set(stdio_names[i], stdio_devices[i]->name);
}
-#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
@@ -956,18 +929,16 @@ int console_init_r(void)
else
flushpoint = PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL;
-#ifdef CONFIG_SPLASH_SCREEN
/*
* suppress all output if splash screen is enabled and we have
* a bmp to display. We redirect the output from frame buffer
* console to serial console in this case or suppress it if
* "silent" mode was requested.
*/
- if (env_get("splashimage") != NULL) {
+ if (IS_ENABLED(CONFIG_SPLASH_SCREEN) && env_get("splashimage")) {
if (!(gd->flags & GD_FLG_SILENT))
outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
}
-#endif
/* Scan devices looking for input and output devices */
list_for_each(pos, list) {
@@ -1001,9 +972,8 @@ int console_init_r(void)
#endif
}
-#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
- stdio_print_current_devices();
-#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
+ if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET))
+ stdio_print_current_devices();
/* Setting environment variables */
for (i = 0; i < MAX_FILES; i++) {
--
2.17.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 2/4] console: add function console_devices_set
2020-12-18 11:46 [PATCH v3 0/4] console: remove #ifdef CONFIG when it is possible Patrick Delaunay
2020-12-18 11:46 ` [PATCH v3 1/4] " Patrick Delaunay
@ 2020-12-18 11:46 ` Patrick Delaunay
2021-01-16 16:24 ` Tom Rini
2020-12-18 11:46 ` [PATCH v3 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD Patrick Delaunay
2020-12-18 11:46 ` [PATCH v3 4/4] console: add console_has_tstc helper function for CONSOLE_MUX Patrick Delaunay
3 siblings, 1 reply; 13+ messages in thread
From: Patrick Delaunay @ 2020-12-18 11:46 UTC (permalink / raw)
To: u-boot
From: Patrick Delaunay <patrick.delaunay@st.com>
Add a new function to access to console_devices only defined if
CONFIG_IS_ENABLED(CONSOLE_MUX).
This path allows to remove #if CONFIG_IS_ENABLED(CONSOLE_MUX)
in console_getc function.
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
(no changes since v1)
common/console.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/common/console.c b/common/console.c
index d225fdd920..036dd0358a 100644
--- a/common/console.c
+++ b/common/console.c
@@ -177,6 +177,11 @@ static struct stdio_dev *tstcdev;
struct stdio_dev **console_devices[MAX_FILES];
int cd_count[MAX_FILES];
+static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev)
+{
+ console_devices[file][0] = dev;
+}
+
/*
* This depends on tstc() always being called before getchar().
* This is guaranteed to be true because this routine is called
@@ -275,6 +280,11 @@ static inline void console_doenv(int file, struct stdio_dev *dev)
}
#endif
#else
+
+static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev)
+{
+}
+
static inline int console_getc(int file)
{
return stdio_devices[file]->getc(stdio_devices[file]);
@@ -958,18 +968,14 @@ int console_init_r(void)
if (outputdev != NULL) {
console_setfile(stdout, outputdev);
console_setfile(stderr, outputdev);
-#if CONFIG_IS_ENABLED(CONSOLE_MUX)
- console_devices[stdout][0] = outputdev;
- console_devices[stderr][0] = outputdev;
-#endif
+ console_devices_set(stdout, outputdev);
+ console_devices_set(stderr, outputdev);
}
/* Initializes input console */
if (inputdev != NULL) {
console_setfile(stdin, inputdev);
-#if CONFIG_IS_ENABLED(CONSOLE_MUX)
- console_devices[stdin][0] = inputdev;
-#endif
+ console_devices_set(stdin, inputdev);
}
if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET))
--
2.17.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD
2020-12-18 11:46 [PATCH v3 0/4] console: remove #ifdef CONFIG when it is possible Patrick Delaunay
2020-12-18 11:46 ` [PATCH v3 1/4] " Patrick Delaunay
2020-12-18 11:46 ` [PATCH v3 2/4] console: add function console_devices_set Patrick Delaunay
@ 2020-12-18 11:46 ` Patrick Delaunay
2020-12-19 3:34 ` Simon Glass
2021-01-16 16:24 ` Tom Rini
2020-12-18 11:46 ` [PATCH v3 4/4] console: add console_has_tstc helper function for CONSOLE_MUX Patrick Delaunay
3 siblings, 2 replies; 13+ messages in thread
From: Patrick Delaunay @ 2020-12-18 11:46 UTC (permalink / raw)
To: u-boot
From: Patrick Delaunay <patrick.delaunay@st.com>
Add helper functions to access to gd->console_out and gd->console_in
with membuff API and replace the #ifdef CONFIG_CONSOLE_RECORD test
by if (IS_ENABLED(CONFIG_CONSOLE_RECORD)) to respect the U-Boot
coding rule.
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
(no changes since v2)
Changes in v2:
- move the tests on gd->flags & GD_FLG_RECORD in helper functions
- remove test on IS_ENABLED(CONFIG_CONSOLE_RECORD)
before to call helper functions
common/console.c | 95 +++++++++++++++++++++++++++++++++++++-----------
1 file changed, 73 insertions(+), 22 deletions(-)
diff --git a/common/console.c b/common/console.c
index 036dd0358a..295c10f242 100644
--- a/common/console.c
+++ b/common/console.c
@@ -88,6 +88,64 @@ static int on_silent(const char *name, const char *value, enum env_op op,
U_BOOT_ENV_CALLBACK(silent, on_silent);
#endif
+#ifdef CONFIG_CONSOLE_RECORD
+/* helper function: access to gd->console_out and gd->console_in */
+static void console_record_putc(const char c)
+{
+ if (!(gd->flags & GD_FLG_RECORD))
+ return;
+ if (gd->console_out.start)
+ membuff_putbyte((struct membuff *)&gd->console_out, c);
+}
+
+static void console_record_puts(const char *s)
+{
+ if (!(gd->flags & GD_FLG_RECORD))
+ return;
+ if (gd->console_out.start)
+ membuff_put((struct membuff *)&gd->console_out, s, strlen(s));
+}
+
+static int console_record_getc(void)
+{
+ if (!(gd->flags & GD_FLG_RECORD))
+ return -1;
+ if (!gd->console_in.start)
+ return -1;
+
+ return membuff_getbyte((struct membuff *)&gd->console_in);
+}
+
+static int console_record_tstc(void)
+{
+ if (!(gd->flags & GD_FLG_RECORD))
+ return 0;
+ if (gd->console_in.start) {
+ if (membuff_peekbyte((struct membuff *)&gd->console_in) != -1)
+ return 1;
+ }
+ return 0;
+}
+#else
+static void console_record_putc(char c)
+{
+}
+
+static void console_record_puts(const char *s)
+{
+}
+
+static int console_record_getc(void)
+{
+ return -1;
+}
+
+static int console_record_tstc(void)
+{
+ return 0;
+}
+#endif
+
#if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
/*
* if overwrite_console returns 1, the stdin, stderr and stdout
@@ -414,21 +472,18 @@ int fprintf(int file, const char *fmt, ...)
int getchar(void)
{
+ int ch;
+
if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
return 0;
if (!gd->have_console)
return 0;
-#ifdef CONFIG_CONSOLE_RECORD
- if (gd->console_in.start) {
- int ch;
+ ch = console_record_getc();
+ if (ch != -1)
+ return ch;
- ch = membuff_getbyte((struct membuff *)&gd->console_in);
- if (ch != -1)
- return 1;
- }
-#endif
if (gd->flags & GD_FLG_DEVINIT) {
/* Get from the standard input */
return fgetc(stdin);
@@ -445,12 +500,10 @@ int tstc(void)
if (!gd->have_console)
return 0;
-#ifdef CONFIG_CONSOLE_RECORD
- if (gd->console_in.start) {
- if (membuff_peekbyte((struct membuff *)&gd->console_in) != -1)
- return 1;
- }
-#endif
+
+ if (console_record_tstc())
+ return 1;
+
if (gd->flags & GD_FLG_DEVINIT) {
/* Test the standard input */
return ftstc(stdin);
@@ -521,10 +574,9 @@ void putc(const char c)
{
if (!gd)
return;
-#ifdef CONFIG_CONSOLE_RECORD
- if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
- membuff_putbyte((struct membuff *)&gd->console_out, c);
-#endif
+
+ console_record_putc(c);
+
/* sandbox can send characters to stdout before it has a console */
if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) {
os_putc(c);
@@ -563,10 +615,9 @@ void puts(const char *s)
{
if (!gd)
return;
-#ifdef CONFIG_CONSOLE_RECORD
- if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
- membuff_put((struct membuff *)&gd->console_out, s, strlen(s));
-#endif
+
+ console_record_puts(s);
+
/* sandbox can send characters to stdout before it has a console */
if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) {
os_puts(s);
--
2.17.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 4/4] console: add console_has_tstc helper function for CONSOLE_MUX
2020-12-18 11:46 [PATCH v3 0/4] console: remove #ifdef CONFIG when it is possible Patrick Delaunay
` (2 preceding siblings ...)
2020-12-18 11:46 ` [PATCH v3 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD Patrick Delaunay
@ 2020-12-18 11:46 ` Patrick Delaunay
2020-12-19 3:34 ` Simon Glass
2021-01-16 16:24 ` Tom Rini
3 siblings, 2 replies; 13+ messages in thread
From: Patrick Delaunay @ 2020-12-18 11:46 UTC (permalink / raw)
To: u-boot
From: Patrick Delaunay <patrick.delaunay@st.com>
Add the helper function console_has_tstc() and replace the test
#if CONFIG_IS_ENABLED(CONSOLE_MUX) to a simple 'if' test to
respect the U-Boot coding rule.
No functional change.
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
Changes in v3:
- update commit message with new function name console_has_tstc
Changes in v2:
- add comment for tstcdev variable
- rename console_tstc_check to console_has_tstc
common/console.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/common/console.c b/common/console.c
index 295c10f242..e82b5d2075 100644
--- a/common/console.c
+++ b/common/console.c
@@ -231,6 +231,7 @@ static bool console_dev_is_serial(struct stdio_dev *sdev)
#if CONFIG_IS_ENABLED(CONSOLE_MUX)
/** Console I/O multiplexing *******************************************/
+/* tstcdev: save the last stdio device with pending characters, with tstc != 0 */
static struct stdio_dev *tstcdev;
struct stdio_dev **console_devices[MAX_FILES];
int cd_count[MAX_FILES];
@@ -256,6 +257,12 @@ static int console_getc(int file)
return ret;
}
+/* Upper layer may have already called tstc(): check the saved result */
+static bool console_has_tstc(void)
+{
+ return !!tstcdev;
+}
+
static int console_tstc(int file)
{
int i, ret;
@@ -348,6 +355,11 @@ static inline int console_getc(int file)
return stdio_devices[file]->getc(stdio_devices[file]);
}
+static bool console_has_tstc(void)
+{
+ return false;
+}
+
static inline int console_tstc(int file)
{
return stdio_devices[file]->tstc(stdio_devices[file]);
@@ -405,18 +417,19 @@ int fgetc(int file)
*/
for (;;) {
WATCHDOG_RESET();
-#if CONFIG_IS_ENABLED(CONSOLE_MUX)
- /*
- * Upper layer may have already called tstc() so
- * check for that first.
- */
- if (tstcdev != NULL)
- return console_getc(file);
- console_tstc(file);
-#else
- if (console_tstc(file))
- return console_getc(file);
-#endif
+ if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
+ /*
+ * Upper layer may have already called tstc() so
+ * check for that first.
+ */
+ if (console_has_tstc())
+ return console_getc(file);
+ console_tstc(file);
+ } else {
+ if (console_tstc(file))
+ return console_getc(file);
+ }
+
/*
* If the watchdog must be rate-limited then it should
* already be handled in board-specific code.
--
2.17.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 1/4] console: remove #ifdef CONFIG when it is possible
2020-12-18 11:46 ` [PATCH v3 1/4] " Patrick Delaunay
@ 2020-12-19 3:34 ` Simon Glass
2021-01-16 16:24 ` Tom Rini
1 sibling, 0 replies; 13+ messages in thread
From: Simon Glass @ 2020-12-19 3:34 UTC (permalink / raw)
To: u-boot
On Fri, 18 Dec 2020 at 04:46, Patrick Delaunay
<patrick.delaunay@foss.st.com> wrote:
>
> From: Patrick Delaunay <patrick.delaunay@st.com>
>
> Remove #ifdef or #ifndef for CONFIG when it is possible to simplify
> the console.c code and respect the U-Boot coding rules.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - update also #ifdef CONFIG_SANDBOX after Simon Glass remark
> (code can't be removed to avoid to rely sandbox on debug uart)
>
> common/console.c | 158 +++++++++++++++++++----------------------------
> 1 file changed, 64 insertions(+), 94 deletions(-)
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD
2020-12-18 11:46 ` [PATCH v3 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD Patrick Delaunay
@ 2020-12-19 3:34 ` Simon Glass
2021-01-04 13:18 ` Patrick DELAUNAY
2021-01-16 16:24 ` Tom Rini
1 sibling, 1 reply; 13+ messages in thread
From: Simon Glass @ 2020-12-19 3:34 UTC (permalink / raw)
To: u-boot
On Fri, 18 Dec 2020 at 04:46, Patrick Delaunay
<patrick.delaunay@foss.st.com> wrote:
>
> From: Patrick Delaunay <patrick.delaunay@st.com>
>
> Add helper functions to access to gd->console_out and gd->console_in
I don't see those in this patch
> with membuff API and replace the #ifdef CONFIG_CONSOLE_RECORD test
> by if (IS_ENABLED(CONFIG_CONSOLE_RECORD)) to respect the U-Boot
> coding rule.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - move the tests on gd->flags & GD_FLG_RECORD in helper functions
> - remove test on IS_ENABLED(CONFIG_CONSOLE_RECORD)
> before to call helper functions
>
> common/console.c | 95 +++++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 73 insertions(+), 22 deletions(-)
>
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 4/4] console: add console_has_tstc helper function for CONSOLE_MUX
2020-12-18 11:46 ` [PATCH v3 4/4] console: add console_has_tstc helper function for CONSOLE_MUX Patrick Delaunay
@ 2020-12-19 3:34 ` Simon Glass
2021-01-16 16:24 ` Tom Rini
1 sibling, 0 replies; 13+ messages in thread
From: Simon Glass @ 2020-12-19 3:34 UTC (permalink / raw)
To: u-boot
On Fri, 18 Dec 2020 at 04:46, Patrick Delaunay
<patrick.delaunay@foss.st.com> wrote:
>
> From: Patrick Delaunay <patrick.delaunay@st.com>
>
> Add the helper function console_has_tstc() and replace the test
> #if CONFIG_IS_ENABLED(CONSOLE_MUX) to a simple 'if' test to
> respect the U-Boot coding rule.
>
> No functional change.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
>
> Changes in v3:
> - update commit message with new function name console_has_tstc
>
> Changes in v2:
> - add comment for tstcdev variable
> - rename console_tstc_check to console_has_tstc
>
> common/console.c | 37 +++++++++++++++++++++++++------------
> 1 file changed, 25 insertions(+), 12 deletions(-)
>
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD
2020-12-19 3:34 ` Simon Glass
@ 2021-01-04 13:18 ` Patrick DELAUNAY
0 siblings, 0 replies; 13+ messages in thread
From: Patrick DELAUNAY @ 2021-01-04 13:18 UTC (permalink / raw)
To: u-boot
On 12/19/20 4:34 AM, Simon Glass wrote:
> On Fri, 18 Dec 2020 at 04:46, Patrick Delaunay
> <patrick.delaunay@foss.st.com> wrote:
>> From: Patrick Delaunay <patrick.delaunay@st.com>
>>
>> Add helper functions to access to gd->console_out and gd->console_in
> I don't see those in this patch
These helper function are console_record_putc() / _puts()? / _getc() /
_tstc();
they use "gd->console_out" and "gd->console_in" only if
CONFIG_CONSOLE_RECORD is defined:
diff --git a/common/console.c b/common/console.c index
036dd0358a..295c10f242 100644
--- a/common/console.c
+++ b/common/console.c
@@ -88,6 +88,64 @@ static int on_silent(const char *name, const char
*value, enum env_op op, U_BOOT_ENV_CALLBACK(silent, on_silent); #endif
+#ifdef CONFIG_CONSOLE_RECORD
+/* helper function: access to gd->console_out and gd->console_in */
...
+#else
... stubs => do nothings
+#endif
>
>> with membuff API and replace the #ifdef CONFIG_CONSOLE_RECORD test
>> by if (IS_ENABLED(CONFIG_CONSOLE_RECORD)) to respect the U-Boot
>> coding rule.
>>
>> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
>> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
>> ---
>>
>> (no changes since v2)
>>
>> Changes in v2:
>> - move the tests on gd->flags & GD_FLG_RECORD in helper functions
>> - remove test on IS_ENABLED(CONFIG_CONSOLE_RECORD)
>> before to call helper functions
>>
>> common/console.c | 95 +++++++++++++++++++++++++++++++++++++-----------
>> 1 file changed, 73 insertions(+), 22 deletions(-)
>>
> Reviewed-by: Simon Glass <sjg@chromium.org>
Regards
Patrick
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 1/4] console: remove #ifdef CONFIG when it is possible
2020-12-18 11:46 ` [PATCH v3 1/4] " Patrick Delaunay
2020-12-19 3:34 ` Simon Glass
@ 2021-01-16 16:24 ` Tom Rini
1 sibling, 0 replies; 13+ messages in thread
From: Tom Rini @ 2021-01-16 16:24 UTC (permalink / raw)
To: u-boot
On Fri, Dec 18, 2020 at 12:46:43PM +0100, Patrick Delaunay wrote:
> From: Patrick Delaunay <patrick.delaunay@st.com>
>
> Remove #ifdef or #ifndef for CONFIG when it is possible to simplify
> the console.c code and respect the U-Boot coding rules.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210116/87a79e8e/attachment.sig>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 2/4] console: add function console_devices_set
2020-12-18 11:46 ` [PATCH v3 2/4] console: add function console_devices_set Patrick Delaunay
@ 2021-01-16 16:24 ` Tom Rini
0 siblings, 0 replies; 13+ messages in thread
From: Tom Rini @ 2021-01-16 16:24 UTC (permalink / raw)
To: u-boot
On Fri, Dec 18, 2020 at 12:46:44PM +0100, Patrick Delaunay wrote:
> From: Patrick Delaunay <patrick.delaunay@st.com>
>
> Add a new function to access to console_devices only defined if
> CONFIG_IS_ENABLED(CONSOLE_MUX).
>
> This path allows to remove #if CONFIG_IS_ENABLED(CONSOLE_MUX)
> in console_getc function.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210116/9409db9f/attachment.sig>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD
2020-12-18 11:46 ` [PATCH v3 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD Patrick Delaunay
2020-12-19 3:34 ` Simon Glass
@ 2021-01-16 16:24 ` Tom Rini
1 sibling, 0 replies; 13+ messages in thread
From: Tom Rini @ 2021-01-16 16:24 UTC (permalink / raw)
To: u-boot
On Fri, Dec 18, 2020 at 12:46:45PM +0100, Patrick Delaunay wrote:
> From: Patrick Delaunay <patrick.delaunay@st.com>
>
> Add helper functions to access to gd->console_out and gd->console_in
> with membuff API and replace the #ifdef CONFIG_CONSOLE_RECORD test
> by if (IS_ENABLED(CONFIG_CONSOLE_RECORD)) to respect the U-Boot
> coding rule.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210116/e3ad4596/attachment.sig>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 4/4] console: add console_has_tstc helper function for CONSOLE_MUX
2020-12-18 11:46 ` [PATCH v3 4/4] console: add console_has_tstc helper function for CONSOLE_MUX Patrick Delaunay
2020-12-19 3:34 ` Simon Glass
@ 2021-01-16 16:24 ` Tom Rini
1 sibling, 0 replies; 13+ messages in thread
From: Tom Rini @ 2021-01-16 16:24 UTC (permalink / raw)
To: u-boot
On Fri, Dec 18, 2020 at 12:46:46PM +0100, Patrick Delaunay wrote:
> From: Patrick Delaunay <patrick.delaunay@st.com>
>
> Add the helper function console_has_tstc() and replace the test
> #if CONFIG_IS_ENABLED(CONSOLE_MUX) to a simple 'if' test to
> respect the U-Boot coding rule.
>
> No functional change.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210116/01765461/attachment.sig>
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2021-01-16 16:24 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18 11:46 [PATCH v3 0/4] console: remove #ifdef CONFIG when it is possible Patrick Delaunay
2020-12-18 11:46 ` [PATCH v3 1/4] " Patrick Delaunay
2020-12-19 3:34 ` Simon Glass
2021-01-16 16:24 ` Tom Rini
2020-12-18 11:46 ` [PATCH v3 2/4] console: add function console_devices_set Patrick Delaunay
2021-01-16 16:24 ` Tom Rini
2020-12-18 11:46 ` [PATCH v3 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD Patrick Delaunay
2020-12-19 3:34 ` Simon Glass
2021-01-04 13:18 ` Patrick DELAUNAY
2021-01-16 16:24 ` Tom Rini
2020-12-18 11:46 ` [PATCH v3 4/4] console: add console_has_tstc helper function for CONSOLE_MUX Patrick Delaunay
2020-12-19 3:34 ` Simon Glass
2021-01-16 16:24 ` Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.