public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: Masahisa Kojima <masahisa.kojima@linaro.org>
Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de,
	ilias.apalodimas@linaro.org, sjg@chromium.org,
	takahiro.akashi@linaro.org, francois.ozog@linaro.org,
	masahisa.kojima@linaro.org, michal.simek@amd.com,
	kory.maincent@bootlin.com, ovidiu.panait@windriver.com,
	ashok.reddy.soma@xilinx.com
Subject: Re: [PATCH v5 11/17] bootmenu: add Kconfig option not to enter U-Boot console
Date: Fri, 29 Apr 2022 10:50:50 +0200 (CEST)	[thread overview]
Message-ID: <d3cd307cc305ebbf@bloch.sibelius.xs4all.nl> (raw)
In-Reply-To: <20220428080950.23509-12-masahisa.kojima@linaro.org> (message from Masahisa Kojima on Thu, 28 Apr 2022 17:09:44 +0900)

> From: Masahisa Kojima <masahisa.kojima@linaro.org>
> Date: Thu, 28 Apr 2022 17:09:44 +0900
> 
> This commit adds the Kconfig option to disable to enter
> the U-Boot console from bootmenu.
> 
> If CMD_BOOTMENU_ENTER_UBOOT_CONSOLE is enabled, "U-Boot console"
> entry is appeared as the last entry in the bootmenu, then user can
> enter U-Boot console.
> 
> If CMD_BOOTMENU_ENTER_UBOOT_CONSOLE is disabled, "Quit" entry
> is appeared as the last entry instead of "U-Boot console".
> When user chooses "Quit" from bootmenu, the following default
> commands are invoked.
> 
>  - "bootefi bootmgr" (if efi bootmgr is enabled)
>  - "run bootcmd"
> 
> If the both commands are executed and returns to the bootmenu,
> the bootmenu will appears again.

I think the default for this option should be "y", otherwise I fear
too many boards will ship with a "locked down" U-Boot where the user
has no way to get at the U-Boot prompt.

> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> ---
> Changes in v5:
> - split into the separate patch
> - clear the console when user select "U-Boot console"
> - if the console is disabled, the last entry title is "Quit"
> 
>  cmd/Kconfig    | 10 ++++++++
>  cmd/bootmenu.c | 69 ++++++++++++++++++++++++++++++++++++++++++--------
>  2 files changed, 68 insertions(+), 11 deletions(-)
> 
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 2b575a2b42..99a1435467 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -356,6 +356,16 @@ config CMD_BOOTMENU
>  	help
>  	  Add an ANSI terminal boot menu command.
>  
> +config CMD_BOOTMENU_ENTER_UBOOT_CONSOLE
> +	bool "Allow Bootmenu to enter the U-Boot console"
> +	depends on CMD_BOOTMENU
> +	default n
> +	help
> +	  Add an entry to enter U-Boot console in bootmenu.
> +	  If this option is disabled, user can not enter
> +	  the U-Boot console from bootmenu. It increases
> +	  the system security.
> +
>  config CMD_ADTIMG
>  	bool "adtimg"
>  	help
> diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
> index afe42b8041..bfbb1b5248 100644
> --- a/cmd/bootmenu.c
> +++ b/cmd/bootmenu.c
> @@ -29,6 +29,13 @@
>   */
>  #define MAX_ENV_SIZE	(9 + 2 + 1)
>  
> +enum bootmenu_ret {
> +	BOOTMENU_RET_SUCCESS = 0,
> +	BOOTMENU_RET_FAIL,
> +	BOOTMENU_RET_QUIT,
> +	BOOTMENU_RET_UPDATED,
> +};
> +
>  enum boot_type {
>  	BOOTMENU_TYPE_NONE = 0,
>  	BOOTMENU_TYPE_BOOTMENU,
> @@ -681,7 +688,12 @@ static struct bootmenu_data *bootmenu_create(int delay)
>  		if (!entry)
>  			goto cleanup;
>  
> -		entry->title = u16_strdup(u"U-Boot console");
> +		/* Add Quit entry if entering U-Boot console is disabled */
> +		if (IS_ENABLED(CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE))
> +			entry->title = u16_strdup(u"U-Boot console");
> +		else
> +			entry->title = u16_strdup(u"Quit");
> +
>  		if (!entry->title) {
>  			free(entry);
>  			goto cleanup;
> @@ -777,15 +789,17 @@ static void handle_uefi_bootnext(void)
>  		run_command("bootefi bootmgr", 0);
>  }
>  
> -static void bootmenu_show(int delay)
> +static enum bootmenu_ret bootmenu_show(int delay)
>  {
> +	int cmd_ret;
>  	int init = 0;
>  	void *choice = NULL;
>  	u16 *title = NULL;
>  	char *command = NULL;
>  	struct menu *menu;
> -	struct bootmenu_data *bootmenu;
>  	struct bootmenu_entry *iter;
> +	int ret = BOOTMENU_RET_SUCCESS;
> +	struct bootmenu_data *bootmenu;
>  	efi_status_t efi_ret = EFI_SUCCESS;
>  	char *option, *sep;
>  
> @@ -797,27 +811,27 @@ static void bootmenu_show(int delay)
>  		option = bootmenu_getoption(0);
>  		if (!option) {
>  			puts("bootmenu option 0 was not found\n");
> -			return;
> +			return BOOTMENU_RET_FAIL;
>  		}
>  		sep = strchr(option, '=');
>  		if (!sep) {
>  			puts("bootmenu option 0 is invalid\n");
> -			return;
> +			return BOOTMENU_RET_FAIL;
>  		}
> -		run_command(sep+1, 0);
> -		return;
> +		cmd_ret = run_command(sep + 1, 0);
> +		return (cmd_ret == CMD_RET_SUCCESS ? BOOTMENU_RET_SUCCESS : BOOTMENU_RET_FAIL);
>  	}
>  
>  	bootmenu = bootmenu_create(delay);
>  	if (!bootmenu)
> -		return;
> +		return BOOTMENU_RET_FAIL;
>  
>  	menu = menu_create(NULL, bootmenu->delay, 1, menu_display_statusline,
>  			   bootmenu_print_entry, bootmenu_choice_entry,
>  			   bootmenu);
>  	if (!menu) {
>  		bootmenu_destroy(bootmenu);
> -		return;
> +		return BOOTMENU_RET_FAIL;
>  	}
>  
>  	for (iter = bootmenu->first; iter; iter = iter->next) {
> @@ -838,6 +852,14 @@ static void bootmenu_show(int delay)
>  		iter = choice;
>  		title = u16_strdup(iter->title);
>  		command = strdup(iter->command);
> +
> +		/* last entry is U-Boot console or Quit */
> +		if (iter->num == iter->menu->count - 1) {
> +			ret = BOOTMENU_RET_QUIT;
> +			goto cleanup;
> +		}
> +	} else {
> +		goto cleanup;
>  	}
>  
>  	/*
> @@ -875,19 +897,44 @@ cleanup:
>  		debug("Starting entry '%ls'\n", title);
>  		free(title);
>  		if (efi_ret == EFI_SUCCESS)
> -			run_command(command, 0);
> +			cmd_ret = run_command(command, 0);
>  		free(command);
>  	}
>  
>  #ifdef CONFIG_POSTBOOTMENU
>  	run_command(CONFIG_POSTBOOTMENU, 0);
>  #endif
> +
> +	if (efi_ret != EFI_SUCCESS || cmd_ret != CMD_RET_SUCCESS)
> +		ret = BOOTMENU_RET_FAIL;
> +
> +	return ret;
>  }
>  
>  #ifdef CONFIG_AUTOBOOT_MENU_SHOW
>  int menu_show(int bootdelay)
>  {
> -	bootmenu_show(bootdelay);
> +	int ret;
> +
> +	while (1) {
> +		ret = bootmenu_show(bootdelay);
> +		bootdelay = -1;
> +		if (ret == BOOTMENU_RET_UPDATED)
> +			continue;
> +
> +		if (!IS_ENABLED(CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE)) {
> +			if (ret == BOOTMENU_RET_QUIT) {
> +				/* default boot process */
> +				if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR))
> +					run_command("bootefi bootmgr", 0);
> +
> +				run_command("run bootcmd", 0);
> +			}
> +		} else {
> +			break;
> +		}
> +	}
> +
>  	return -1; /* -1 - abort boot and run monitor code */
>  }
>  #endif
> -- 
> 2.17.1
> 
> 

  reply	other threads:[~2022-04-29  8:50 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28  8:09 [PATCH v5 00/17] enable menu-driven boot device selection Masahisa Kojima
2022-04-28  8:09 ` [PATCH v5 01/17] lib/charset: add u16_strlcat() function Masahisa Kojima
2022-04-29 19:36   ` Heinrich Schuchardt
2022-04-28  8:09 ` [PATCH v5 02/17] test: unit test for u16_strlcat() Masahisa Kojima
2022-04-28  8:09 ` [PATCH v5 03/17] menu: always show the menu regardless of the number of entry Masahisa Kojima
2022-05-01 15:37   ` Heinrich Schuchardt
2022-04-28  8:09 ` [PATCH v5 04/17] menu: menu_get_choice() return -ENOENT if menu item is empty Masahisa Kojima
2022-04-29 19:38   ` Heinrich Schuchardt
2022-04-28  8:09 ` [PATCH v5 05/17] efi_loader: export efi_locate_device_handle() Masahisa Kojima
2022-05-01 18:53   ` Heinrich Schuchardt
2022-05-04  9:17     ` Ilias Apalodimas
2022-04-28  8:09 ` [PATCH v5 06/17] efi_loader: bootmgr: add booting from removable media Masahisa Kojima
2022-04-29 17:03   ` Heinrich Schuchardt
2022-05-05 12:05     ` Mark Kettenis
2022-05-05 12:20       ` Heinrich Schuchardt
2022-05-05 12:35         ` Heinrich Schuchardt
2022-05-05 13:25           ` Mark Kettenis
2022-05-05 12:47       ` Mark Kettenis
2022-05-12  9:12         ` AKASHI Takahiro
2022-05-12 10:34           ` Heinrich Schuchardt
2022-04-28  8:09 ` [PATCH v5 07/17] bootmenu: flush input buffer before waiting user key input Masahisa Kojima
2022-04-29 19:46   ` Heinrich Schuchardt
2022-05-09  8:33     ` Masahisa Kojima
2022-04-28  8:09 ` [PATCH v5 08/17] bootmenu: update bootmenu_entry structure Masahisa Kojima
2022-04-29 19:51   ` Heinrich Schuchardt
2022-05-01 20:54     ` Heinrich Schuchardt
2022-05-09  8:54       ` Masahisa Kojima
2022-04-28  8:09 ` [PATCH v5 09/17] bootmenu: add UEFI boot entry into bootmenu Masahisa Kojima
2022-05-01 21:44   ` Heinrich Schuchardt
2022-05-09  8:59     ` Masahisa Kojima
2022-04-28  8:09 ` [PATCH v5 10/17] bootmenu: add distro boot entry Masahisa Kojima
2022-05-01 21:48   ` Heinrich Schuchardt
2022-05-12  8:44     ` Takahiro Akashi
2022-05-12 10:39       ` Heinrich Schuchardt
2022-05-12 11:42         ` Mark Kettenis
2022-04-28  8:09 ` [PATCH v5 11/17] bootmenu: add Kconfig option not to enter U-Boot console Masahisa Kojima
2022-04-29  8:50   ` Mark Kettenis [this message]
2022-04-28  8:09 ` [PATCH v5 12/17] bootmenu: factor out the user input handling Masahisa Kojima
2022-04-28  8:09 ` [PATCH v5 13/17] efi_loader: menu-driven addition of UEFI boot option Masahisa Kojima
2022-04-28 16:33   ` Heinrich Schuchardt
2022-04-29 10:56     ` Heinrich Schuchardt
2022-04-30 12:49       ` Heinrich Schuchardt
2022-05-06 17:30         ` Heinrich Schuchardt
2022-05-06 18:10           ` Mark Kettenis
2022-05-06 18:16             ` Heinrich Schuchardt
2022-05-09  9:27               ` Masahisa Kojima
2022-05-09 12:56                 ` Heinrich Schuchardt
2022-04-28  8:09 ` [PATCH v5 14/17] efi_loader: menu-driven deletion of UEFI boot variable Masahisa Kojima
2022-04-28  8:09 ` [PATCH v5 15/17] efi_loader: menu-driven update of UEFI bootorder variable Masahisa Kojima
2022-04-28  8:09 ` [PATCH v5 16/17] bootmenu: add removable media entries Masahisa Kojima
2022-04-28 16:53   ` Heinrich Schuchardt
2022-05-09  8:23     ` Masahisa Kojima
2022-05-09 13:01       ` Heinrich Schuchardt
2022-05-16  9:20         ` Masahisa Kojima
2022-04-28  8:09 ` [PATCH v5 17/17] doc:bootmenu: add UEFI boot and distro boot support description Masahisa Kojima
2022-04-28 16:31 ` [PATCH v5 00/17] enable menu-driven boot device selection Heinrich Schuchardt
2022-04-28 16:58   ` Heinrich Schuchardt
2022-04-29  8:45 ` Mark Kettenis

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=d3cd307cc305ebbf@bloch.sibelius.xs4all.nl \
    --to=mark.kettenis@xs4all.nl \
    --cc=ashok.reddy.soma@xilinx.com \
    --cc=francois.ozog@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kory.maincent@bootlin.com \
    --cc=masahisa.kojima@linaro.org \
    --cc=michal.simek@amd.com \
    --cc=ovidiu.panait@windriver.com \
    --cc=sjg@chromium.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.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