[U-Boot] [PATCH] menu: don't bother going interactive with just one menu item

If there is only one menu item available, prompting user to enter choice makes little sense and just causes unnecessary boot delay. This change makes menu_get_choice return the only one item when there is no other choices.
Signed-off-by: Leon Yu leoyu@nvidia.com Cc: Tom Warren twarren@nvidia.com Cc: Stephen Warren swarren@nvidia.com Cc: Thierry Reding treding@nvidia.com --- common/menu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/common/menu.c b/common/menu.c index 0f0a29ac2ee3..7b66d199a9b1 100644 --- a/common/menu.c +++ b/common/menu.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Copyright 2010-2011 Calxeda, Inc. + * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. */
#include <common.h> @@ -39,6 +40,7 @@ struct menu { char *(*item_choice)(void *); void *item_choice_data; struct list_head items; + int item_cnt; };
/* @@ -271,7 +273,7 @@ int menu_get_choice(struct menu *m, void **choice) if (!m || !choice) return -EINVAL;
- if (!m->prompt) + if (!m->prompt || m->item_cnt == 1) return menu_default_choice(m, choice);
return menu_interactive_choice(m, choice); @@ -323,6 +325,7 @@ int menu_item_add(struct menu *m, char *item_key, void *item_data) item->data = item_data;
list_add_tail(&item->list, &m->items); + m->item_cnt++;
return 1; } @@ -374,6 +377,7 @@ struct menu *menu_create(char *title, int timeout, int prompt, m->item_data_print = item_data_print; m->item_choice = item_choice; m->item_choice_data = item_choice_data; + m->item_cnt = 0;
if (title) { m->title = strdup(title);

imho this makes it impossible to get into uboot-console which is not a "real" menuitem
it is only shown after the list of defined Menuitems
http://git.denx.de/?p=u-boot.git;a=blob;f=cmd/bootmenu.c;h=7f88c1ed63252ba04...
regards Frank

On Fri, Jun 21, 2019 at 09:07:39PM +0200, Frank Wunderlich wrote:
imho this makes it impossible to get into uboot-console which is not a "real" menuitem
it is only shown after the list of defined Menuitems
http://git.denx.de/?p=u-boot.git;a=blob;f=cmd/bootmenu.c;h=7f88c1ed63252ba04...
uboot-console IS a menuitem. It's just not populated from bootmenu_$ environment variables but appended by bootmenu_create. Apart from that, things work in the same way. So the behavior with this change is:
1) If no bootmenu_$ env. variable is defined, do_bootmenu will skip selection and get into console which is the only option in the menu. 2) With at least one valid bootmenu_$, do_bootmenu displays those option(s) from env along with "U-Boot console" and waits for user's input.
Leon
----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -----------------------------------------------------------------------------------

On Fri, Jun 21, 2019 at 12:12:39PM +0800, Leon Yu wrote:
If there is only one menu item available, prompting user to enter choice makes little sense and just causes unnecessary boot delay. This change makes menu_get_choice return the only one item when there is no other choices.
Signed-off-by: Leon Yu leoyu@nvidia.com Cc: Tom Warren twarren@nvidia.com Cc: Stephen Warren swarren@nvidia.com Cc: Thierry Reding treding@nvidia.com
As you note in a follow up to Frank's comment this is a behavior change that can make it harder to get into U-Boot console in some cases. Can you please expand a bit more on the case where we are using a menu and waiting the defined number of seconds is a problem (and not addressed well enough by changing the timeout, which is configurable, yes?) ? Thanks!

On Wed, Jul 17, 2019 at 11:58:12AM -0400, Tom Rini wrote:
On Fri, Jun 21, 2019 at 12:12:39PM +0800, Leon Yu wrote:
If there is only one menu item available, prompting user to enter choice makes little sense and just causes unnecessary boot delay. This change makes menu_get_choice return the only one item when there is no other choices.
As you note in a follow up to Frank's comment this is a behavior change that can make it harder to get into U-Boot console in some cases. Can you please expand a bit more on the case where we are using a menu and waiting the defined number of seconds is a problem (and not addressed well enough by changing the timeout, which is configurable, yes?) ? Thanks!
-- Tom
Hi Tom,
Minimal non-zero timeout is one second, which is a bit too short for users to read and/or select but also too long for boot time critical applications. We all know how difficult it can be to save one more second boot time in bootloaders.
As for Frank's earlier comment, his concerns is about unable to enter console because 'U-Boot console' isn't a real menuitem in bootmenu. That's not true. 'U-Boot console' is just automatically populated, rather than from envrironment variables. It's still listed as an item in boot menu. So with the proposed patch, situations are:
a) If no bootmenu_$ env. variable is present, 'U-Boot console' is the only item and will be chosen immediately. So console _will_ be entered as a result.
b) At least one bootmenu_$ env. variable exists, behavior remains the same.
Yes, behavior is changed but just becomes quicker. Its result will remain the same. People can have luxurious time to select from multiple choices and will be fast-forwarded to the only one option which they have to select anyway.
People might wonder why using a menu for boot time critical applications -- this patch is to save time for pxe boot with one default option while still can have sufficient timeout for multiple choices.
What do you think, Tom? Please let me know if I'm missing something, thanks!
Leon
----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -----------------------------------------------------------------------------------
participants (3)
-
Frank Wunderlich
-
Leon Yu
-
Tom Rini