mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] console: add new CONFIG_CONSOLE_DISABLE_INPUT option
@ 2021-09-15 12:36 Ahmad Fatoum
  2021-09-16 11:48 ` Christian Melki
  2021-10-02  9:26 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2021-09-15 12:36 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

From: Rouven Czerwinski <r.czerwinski@pengutronix.de>

Add CONFIG_CONSOLE_DISABLE_INPUT to initialize the consoles without
input support, making default bootup effectively non-interactive.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 is <20201013075925.2984-1-r.czerwinski@pengutronix.de>
v1 -> v2:
  - Make it the default for CONSOLE_NONE. This allows skipping
    count down there early.
  - rename write-only to disable input. This is arguably clearer
  - allow re-enabling input on a per console basis. This way
    e.g. a gpio-key with limited function can be reenabled,
    but all other consoles have input disabled by default.
  - add new CONSOLE_STDIOE to make the three bits easier to
    write as a group.
---
 common/Kconfig          | 11 +++++++++++
 common/console.c        | 12 +++++++-----
 common/console_simple.c |  5 ++++-
 common/startup.c        |  5 +++++
 include/console.h       |  2 ++
 5 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index a9feae2ae866..9ae9238f88dc 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -812,6 +812,17 @@ config CONSOLE_ALLOW_COLOR
 	  compile time default for colored console output. After boot it
 	  can be controlled using global.allow_color.
 
+config CONSOLE_DISABLE_INPUT
+	prompt "Disable input on all consoles by default (non-interactive)"
+	def_bool CONSOLE_NONE
+	help
+	  If enabled, all consoles are initially configured to not accept any input,
+	  making the consoles effectively non-interactive.
+	  The active device parameter can be used to override this on a per-console
+	  basis.
+	  CAUTION: this will also disable input devices by default, since they are
+	  registered as consoles.
+
 config PBL_CONSOLE
 	depends on PBL_IMAGE
 	depends on !CONSOLE_NONE
diff --git a/common/console.c b/common/console.c
index ad1a6aaab2a0..0368c72d0b10 100644
--- a/common/console.c
+++ b/common/console.c
@@ -328,7 +328,7 @@ int console_register(struct console_device *newcdev)
 		return of_platform_populate(serdev_node, NULL, dev);
 
 	if (newcdev->dev && of_device_is_stdout_path(newcdev->dev, &baudrate)) {
-		activate = 1;
+		activate = CONSOLE_STDIOE;
 		console_set_stdoutpath(newcdev, baudrate);
 	}
 
@@ -349,16 +349,18 @@ int console_register(struct console_device *newcdev)
 
 	if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) {
 		if (list_empty(&console_list))
-			activate = 1;
+			activate = CONSOLE_STDIOE;
 	} else if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_ALL)) {
-		activate = 1;
+		activate = CONSOLE_STDIOE;
 	}
 
 	list_add_tail(&newcdev->list, &console_list);
 
+	if (IS_ENABLED(CONFIG_CONSOLE_DISABLE_INPUT))
+		activate &= ~CONSOLE_STDIN;
+
 	if (activate)
-		console_set_active(newcdev, CONSOLE_STDIN |
-				CONSOLE_STDOUT | CONSOLE_STDERR);
+		console_set_active(newcdev, activate);
 
 	/* expose console as device in fs */
 	newcdev->devfs.name = basprintf("%s%d", newcdev->class_dev.name,
diff --git a/common/console_simple.c b/common/console_simple.c
index 42224842c5ea..3b95570e5e76 100644
--- a/common/console_simple.c
+++ b/common/console_simple.c
@@ -92,7 +92,10 @@ int console_register(struct console_device *newcdev)
 		newcdev->setbrg(newcdev, newcdev->baudrate);
 	}
 
-	newcdev->f_active = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
+	newcdev->f_active = CONSOLE_STDIOE;
+
+	if (IS_ENABLED(CONFIG_CONSOLE_DISABLE_INPUT))
+		newcdev->f_active = ~CONSOLE_STDIN;
 
 	barebox_banner();
 
diff --git a/common/startup.c b/common/startup.c
index d170cb8a7c5a..0c7033f38186 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -241,6 +241,11 @@ enum autoboot_state do_autoboot_countdown(void)
 	if (autoboot_state != AUTOBOOT_UNKNOWN)
 		return autoboot_state;
 
+	if (IS_ENABLED(CONFIG_CONSOLE_DISABLE_INPUT)) {
+		printf("\nNon-interactive console, booting system\n");
+		return autoboot_state = AUTOBOOT_BOOT;
+	}
+
 	if (global_autoboot_state != AUTOBOOT_COUNTDOWN)
 		return global_autoboot_state;
 
diff --git a/include/console.h b/include/console.h
index a71d0da42ed0..5d5783ca6668 100644
--- a/include/console.h
+++ b/include/console.h
@@ -18,6 +18,8 @@
 #define CONSOLE_STDOUT          (1 << 1)
 #define CONSOLE_STDERR          (1 << 2)
 
+#define CONSOLE_STDIOE          (CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR)
+
 enum console_mode {
 	CONSOLE_MODE_NORMAL,
 	CONSOLE_MODE_RS485,
-- 
2.33.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] console: add new CONFIG_CONSOLE_DISABLE_INPUT option
  2021-09-15 12:36 [PATCH v2] console: add new CONFIG_CONSOLE_DISABLE_INPUT option Ahmad Fatoum
@ 2021-09-16 11:48 ` Christian Melki
  2021-10-02  9:26 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Melki @ 2021-09-16 11:48 UTC (permalink / raw)
  To: Ahmad Fatoum, barebox; +Cc: Rouven Czerwinski

Works as expected on top of 2021.08.

Tested-by: Christian Melki <christian.melki@t2data.com>

On 9/15/21 2:36 PM, Ahmad Fatoum wrote:
> From: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> 
> Add CONFIG_CONSOLE_DISABLE_INPUT to initialize the consoles without
> input support, making default bootup effectively non-interactive.
> 
> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 is <20201013075925.2984-1-r.czerwinski@pengutronix.de>
> v1 -> v2:
>    - Make it the default for CONSOLE_NONE. This allows skipping
>      count down there early.
>    - rename write-only to disable input. This is arguably clearer
>    - allow re-enabling input on a per console basis. This way
>      e.g. a gpio-key with limited function can be reenabled,
>      but all other consoles have input disabled by default.
>    - add new CONSOLE_STDIOE to make the three bits easier to
>      write as a group.
> ---
>   common/Kconfig          | 11 +++++++++++
>   common/console.c        | 12 +++++++-----
>   common/console_simple.c |  5 ++++-
>   common/startup.c        |  5 +++++
>   include/console.h       |  2 ++
>   5 files changed, 29 insertions(+), 6 deletions(-)
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index a9feae2ae866..9ae9238f88dc 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -812,6 +812,17 @@ config CONSOLE_ALLOW_COLOR
>   	  compile time default for colored console output. After boot it
>   	  can be controlled using global.allow_color.
>   
> +config CONSOLE_DISABLE_INPUT
> +	prompt "Disable input on all consoles by default (non-interactive)"
> +	def_bool CONSOLE_NONE
> +	help
> +	  If enabled, all consoles are initially configured to not accept any input,
> +	  making the consoles effectively non-interactive.
> +	  The active device parameter can be used to override this on a per-console
> +	  basis.
> +	  CAUTION: this will also disable input devices by default, since they are
> +	  registered as consoles.
> +
>   config PBL_CONSOLE
>   	depends on PBL_IMAGE
>   	depends on !CONSOLE_NONE
> diff --git a/common/console.c b/common/console.c
> index ad1a6aaab2a0..0368c72d0b10 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -328,7 +328,7 @@ int console_register(struct console_device *newcdev)
>   		return of_platform_populate(serdev_node, NULL, dev);
>   
>   	if (newcdev->dev && of_device_is_stdout_path(newcdev->dev, &baudrate)) {
> -		activate = 1;
> +		activate = CONSOLE_STDIOE;
>   		console_set_stdoutpath(newcdev, baudrate);
>   	}
>   
> @@ -349,16 +349,18 @@ int console_register(struct console_device *newcdev)
>   
>   	if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) {
>   		if (list_empty(&console_list))
> -			activate = 1;
> +			activate = CONSOLE_STDIOE;
>   	} else if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_ALL)) {
> -		activate = 1;
> +		activate = CONSOLE_STDIOE;
>   	}
>   
>   	list_add_tail(&newcdev->list, &console_list);
>   
> +	if (IS_ENABLED(CONFIG_CONSOLE_DISABLE_INPUT))
> +		activate &= ~CONSOLE_STDIN;
> +
>   	if (activate)
> -		console_set_active(newcdev, CONSOLE_STDIN |
> -				CONSOLE_STDOUT | CONSOLE_STDERR);
> +		console_set_active(newcdev, activate);
>   
>   	/* expose console as device in fs */
>   	newcdev->devfs.name = basprintf("%s%d", newcdev->class_dev.name,
> diff --git a/common/console_simple.c b/common/console_simple.c
> index 42224842c5ea..3b95570e5e76 100644
> --- a/common/console_simple.c
> +++ b/common/console_simple.c
> @@ -92,7 +92,10 @@ int console_register(struct console_device *newcdev)
>   		newcdev->setbrg(newcdev, newcdev->baudrate);
>   	}
>   
> -	newcdev->f_active = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
> +	newcdev->f_active = CONSOLE_STDIOE;
> +
> +	if (IS_ENABLED(CONFIG_CONSOLE_DISABLE_INPUT))
> +		newcdev->f_active = ~CONSOLE_STDIN;
>   
>   	barebox_banner();
>   
> diff --git a/common/startup.c b/common/startup.c
> index d170cb8a7c5a..0c7033f38186 100644
> --- a/common/startup.c
> +++ b/common/startup.c
> @@ -241,6 +241,11 @@ enum autoboot_state do_autoboot_countdown(void)
>   	if (autoboot_state != AUTOBOOT_UNKNOWN)
>   		return autoboot_state;
>   
> +	if (IS_ENABLED(CONFIG_CONSOLE_DISABLE_INPUT)) {
> +		printf("\nNon-interactive console, booting system\n");
> +		return autoboot_state = AUTOBOOT_BOOT;
> +	}
> +
>   	if (global_autoboot_state != AUTOBOOT_COUNTDOWN)
>   		return global_autoboot_state;
>   
> diff --git a/include/console.h b/include/console.h
> index a71d0da42ed0..5d5783ca6668 100644
> --- a/include/console.h
> +++ b/include/console.h
> @@ -18,6 +18,8 @@
>   #define CONSOLE_STDOUT          (1 << 1)
>   #define CONSOLE_STDERR          (1 << 2)
>   
> +#define CONSOLE_STDIOE          (CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR)
> +
>   enum console_mode {
>   	CONSOLE_MODE_NORMAL,
>   	CONSOLE_MODE_RS485,
> 

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] console: add new CONFIG_CONSOLE_DISABLE_INPUT option
  2021-09-15 12:36 [PATCH v2] console: add new CONFIG_CONSOLE_DISABLE_INPUT option Ahmad Fatoum
  2021-09-16 11:48 ` Christian Melki
@ 2021-10-02  9:26 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2021-10-02  9:26 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox, Rouven Czerwinski

On Wed, Sep 15, 2021 at 02:36:44PM +0200, Ahmad Fatoum wrote:
> From: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> 
> Add CONFIG_CONSOLE_DISABLE_INPUT to initialize the consoles without
> input support, making default bootup effectively non-interactive.
> 
> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 is <20201013075925.2984-1-r.czerwinski@pengutronix.de>
> v1 -> v2:
>   - Make it the default for CONSOLE_NONE. This allows skipping
>     count down there early.
>   - rename write-only to disable input. This is arguably clearer
>   - allow re-enabling input on a per console basis. This way
>     e.g. a gpio-key with limited function can be reenabled,
>     but all other consoles have input disabled by default.
>   - add new CONSOLE_STDIOE to make the three bits easier to
>     write as a group.
> ---
>  common/Kconfig          | 11 +++++++++++
>  common/console.c        | 12 +++++++-----
>  common/console_simple.c |  5 ++++-
>  common/startup.c        |  5 +++++
>  include/console.h       |  2 ++
>  5 files changed, 29 insertions(+), 6 deletions(-)

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-02  9:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-15 12:36 [PATCH v2] console: add new CONFIG_CONSOLE_DISABLE_INPUT option Ahmad Fatoum
2021-09-16 11:48 ` Christian Melki
2021-10-02  9:26 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox