diff options
author | Leon Yu <leoyu@nvidia.com> | 2019-06-21 12:12:39 +0800 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2019-07-24 13:16:29 -0400 |
commit | dfaad8208f069f95d35f52c4cc69b1a05cd60f75 (patch) | |
tree | e46c6a1303ef7cfee8c5e301e4c6b03e59b95542 /common/menu.c | |
parent | be683756f620349966e0ebb4a5e02e5ff03c8a8e (diff) | |
download | u-boot-dfaad8208f069f95d35f52c4cc69b1a05cd60f75.zip u-boot-dfaad8208f069f95d35f52c4cc69b1a05cd60f75.tar.gz u-boot-dfaad8208f069f95d35f52c4cc69b1a05cd60f75.tar.bz2 |
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>
Diffstat (limited to 'common/menu.c')
-rw-r--r-- | common/menu.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/common/menu.c b/common/menu.c index 0f0a29a..7b66d19 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); |