From: Sascha Hauer <s.hauer@pengutronix.de>
To: Fabian Pflug <f.pflug@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 1/3] startup: check for console before showing menu
Date: Wed, 29 Oct 2025 10:06:00 +0100	[thread overview]
Message-ID: <aQHY-GhxsmTacEnJ@pengutronix.de> (raw)
In-Reply-To: <20251028154453.2990491-1-f.pflug@pengutronix.de>
On Tue, Oct 28, 2025 at 04:43:24PM +0100, Fabian Pflug wrote:
> If there is no input available or possible due to policy settings, it
> does not make sense to show a menu and ask for input.
> 
> Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
> ---
> v2:
> Remove CONSOLE_DISABLE_INPUT from check
>  common/startup.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/common/startup.c b/common/startup.c
> index 8d36ffceb4..4313435f05 100644
> --- a/common/startup.c
> +++ b/common/startup.c
> @@ -45,6 +45,7 @@
>  #include <pbl/handoff-data.h>
>  #include <libfile.h>
>  #include <fuzz.h>
> +#include <security/config.h>
>  
>  extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
>  		  __barebox_initcalls_end[];
> @@ -361,14 +362,15 @@ static int run_init(void)
>  		run_shell();
>  	}
>  
> -	do {
> -		/*
> -		 * Let's run the command once at least, so an error
> -		 * message is printed if the file doesn't exist
> -		 */
> -		run_command(MENUFILE);
> -	} while (stat(MENUFILE, &s) == 0);
> -
> +	if(IS_ALLOWED(SCONFIG_CONSOLE_INPUT)) {
> +		do {
> +			/*
> +			* Let's run the command once at least, so an error
> +			* message is printed if the file doesn't exist
> +			*/
> +			run_command(MENUFILE);
> +		} while (stat(MENUFILE, &s) == 0);
> +	}
When console input is not allowed then there's no point in calling
run_shell() right above, also calling eth_open_all() likely isn't
useful.
I think the last useful thing we do with console input disabled is this:
	if (autoboot == AUTOBOOT_BOOT)
		run_command("boot");
After that point there's nothing left to do, so we could directly
do a
	if (!IS_ALLOWED(SCONFIG_CONSOLE_INPUT))
		hang();
This only misses one point that is currently not handled: autoboot could
have been interrupted because console_countdown_abort() has been called,
for example by fastboot in which case we don't want to hang() but
instead sleep forever.
So the whole logic would be:
	if (autoboot == AUTOBOOT_BOOT)
                run_command("boot");
	if (!IS_ALLOWED(SCONFIG_CONSOLE_INPUT)) {
		if (autoboot == AUTOBOOT_BOOT) {
			hang();
		} else {
			while (true) {
				sleep(1);
			}
		}
	}
	... run_shell(), call menu, ...
Maybe this needs some refactoring for readability.
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 |
     prev parent reply	other threads:[~2025-10-29  9:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28 15:43 Fabian Pflug
2025-10-28 15:43 ` [PATCH v2 2/3] console_common: get_first_active: respect security policy Fabian Pflug
2025-10-29  7:04   ` Ahmad Fatoum
2025-10-28 15:43 ` [PATCH 3/3] startup: mount ps only on policy FS_EXTERNAL Fabian Pflug
2025-10-29  9:06 ` Sascha Hauer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=aQHY-GhxsmTacEnJ@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=f.pflug@pengutronix.de \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox