2022-08-07 10:06:56 +00:00
|
|
|
From 5a15437610e8e8c68dc347845a83d0cbad80ca08 Mon Sep 17 00:00:00 2001
|
2021-02-20 13:04:38 +00:00
|
|
|
From: Weijie Gao <weijie.gao@mediatek.com>
|
|
|
|
Date: Tue, 19 Jan 2021 10:58:48 +0800
|
2022-08-07 10:06:56 +00:00
|
|
|
Subject: [PATCH 51/71] cmd: bootmenu: add ability to select item by shortkey
|
2021-02-20 13:04:38 +00:00
|
|
|
|
|
|
|
Add ability to use shortkey to select item for bootmenu command
|
|
|
|
|
|
|
|
Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
|
|
|
|
---
|
2022-08-07 10:06:56 +00:00
|
|
|
cmd/bootmenu.c | 34 ++++++++++++++++++++++++-----
|
|
|
|
common/menu.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++--
|
|
|
|
include/menu.h | 12 +++++++----
|
|
|
|
3 files changed, 93 insertions(+), 11 deletions(-)
|
2021-02-20 13:04:38 +00:00
|
|
|
|
|
|
|
--- a/cmd/bootmenu.c
|
|
|
|
+++ b/cmd/bootmenu.c
|
2024-10-07 17:31:58 +00:00
|
|
|
@@ -88,6 +88,7 @@ static char *bootmenu_choice_entry(void
|
2022-07-11 10:02:49 +00:00
|
|
|
struct bootmenu_data *menu = data;
|
|
|
|
struct bootmenu_entry *iter;
|
2023-04-11 23:21:22 +00:00
|
|
|
enum bootmenu_key key = BKEY_NONE;
|
2022-07-11 10:02:49 +00:00
|
|
|
+ int choice = -1;
|
|
|
|
int i;
|
2021-02-20 13:04:38 +00:00
|
|
|
|
2023-04-11 23:21:22 +00:00
|
|
|
cli_ch_init(cch);
|
2024-10-07 17:31:58 +00:00
|
|
|
@@ -95,10 +96,10 @@ static char *bootmenu_choice_entry(void
|
2022-07-11 10:02:49 +00:00
|
|
|
while (1) {
|
|
|
|
if (menu->delay >= 0) {
|
|
|
|
/* Autoboot was not stopped */
|
2023-04-11 23:21:22 +00:00
|
|
|
- key = bootmenu_autoboot_loop(menu, cch);
|
|
|
|
+ key = bootmenu_autoboot_loop(menu, cch, &choice);
|
2022-07-11 10:02:49 +00:00
|
|
|
} else {
|
|
|
|
/* Some key was pressed, so autoboot was stopped */
|
2023-04-11 23:21:22 +00:00
|
|
|
- key = bootmenu_loop(menu, cch);
|
|
|
|
+ key = bootmenu_loop(menu, cch, &choice);
|
2022-07-11 10:02:49 +00:00
|
|
|
}
|
2021-02-20 13:04:38 +00:00
|
|
|
|
2022-07-11 10:02:49 +00:00
|
|
|
switch (key) {
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -114,6 +115,12 @@ static char *bootmenu_choice_entry(void
|
2022-07-11 10:02:49 +00:00
|
|
|
++menu->active;
|
|
|
|
/* no menu key selected, regenerate menu */
|
|
|
|
return NULL;
|
2023-04-11 23:21:22 +00:00
|
|
|
+ case BKEY_CHOICE:
|
2022-07-11 10:02:49 +00:00
|
|
|
+ menu->active = choice;
|
|
|
|
+ if (!menu->last_choiced) {
|
|
|
|
+ menu->last_choiced = true;
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
2023-04-11 23:21:22 +00:00
|
|
|
case BKEY_SELECT:
|
2022-07-11 10:02:49 +00:00
|
|
|
iter = menu->first;
|
|
|
|
for (i = 0; i < menu->active; ++i)
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -182,6 +189,9 @@ static int prepare_bootmenu_entry(struct
|
2022-08-07 10:06:56 +00:00
|
|
|
unsigned short int i = *index;
|
|
|
|
struct bootmenu_entry *entry = NULL;
|
|
|
|
struct bootmenu_entry *iter = *current;
|
|
|
|
+ char *choice_option;
|
|
|
|
+ char choice_char;
|
|
|
|
+ int len;
|
|
|
|
|
|
|
|
while ((option = bootmenu_getoption(i))) {
|
|
|
|
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -196,11 +206,24 @@ static int prepare_bootmenu_entry(struct
|
2022-07-11 10:02:49 +00:00
|
|
|
if (!entry)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
- entry->title = strndup(option, sep - option);
|
2022-08-07 10:06:56 +00:00
|
|
|
+ /* Add KEY_CHOICE support: '%d. %s\0' : len --> len + 4 */
|
|
|
|
+ len = sep - option + 4;
|
|
|
|
+ choice_option = malloc(len);
|
|
|
|
+ if (!choice_option) {
|
|
|
|
+ free(entry->title);
|
|
|
|
+ free(entry);
|
|
|
|
+ return -ENOMEM;
|
|
|
|
+ }
|
|
|
|
+ if (!get_choice_char(i, &choice_char))
|
|
|
|
+ len = snprintf(choice_option, len, "%c. %s", choice_char, option);
|
|
|
|
+ else
|
|
|
|
+ len = snprintf(choice_option, len, " %s", option);
|
|
|
|
+ entry->title = strndup(choice_option, len);
|
2022-07-11 10:02:49 +00:00
|
|
|
if (!entry->title) {
|
|
|
|
free(entry);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2022-08-07 10:06:56 +00:00
|
|
|
+ free(choice_option);
|
2022-07-11 10:02:49 +00:00
|
|
|
|
|
|
|
entry->command = strdup(sep + 1);
|
|
|
|
if (!entry->command) {
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -347,6 +370,7 @@ static struct bootmenu_data *bootmenu_cr
|
2022-07-11 10:02:49 +00:00
|
|
|
menu->active = 0;
|
2024-10-31 21:08:10 +00:00
|
|
|
menu->last_active = -1;
|
2022-07-11 10:02:49 +00:00
|
|
|
menu->first = NULL;
|
|
|
|
+ menu->last_choiced = false;
|
|
|
|
|
|
|
|
default_str = env_get("bootmenu_default");
|
|
|
|
if (default_str)
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -382,9 +406,9 @@ static struct bootmenu_data *bootmenu_cr
|
2022-07-11 10:02:49 +00:00
|
|
|
|
2024-07-05 05:52:06 +00:00
|
|
|
/* Add Quit entry if exiting bootmenu is disabled */
|
2022-07-11 10:02:49 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE))
|
2024-07-05 05:52:06 +00:00
|
|
|
- entry->title = strdup("Exit");
|
|
|
|
+ entry->title = strdup("0. Exit");
|
2022-07-11 10:02:49 +00:00
|
|
|
else
|
|
|
|
- entry->title = strdup("Quit");
|
|
|
|
+ entry->title = strdup("0. Quit");
|
|
|
|
|
|
|
|
if (!entry->title) {
|
|
|
|
free(entry);
|
|
|
|
--- a/common/menu.c
|
|
|
|
+++ b/common/menu.c
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -49,6 +49,33 @@ struct menu {
|
2022-07-11 10:02:49 +00:00
|
|
|
int item_cnt;
|
|
|
|
};
|
|
|
|
|
2022-08-07 10:06:56 +00:00
|
|
|
+const char choice_chars[] = {
|
|
|
|
+ '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
|
|
|
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
|
|
|
+ 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
|
|
|
|
+ 'u', 'v', 'w', 'x', 'y', 'z'
|
|
|
|
+};
|
|
|
|
+
|
2021-02-20 13:04:38 +00:00
|
|
|
+static int find_choice(char choice)
|
|
|
|
+{
|
|
|
|
+ int i;
|
|
|
|
+
|
|
|
|
+ for (i = 0; i < ARRAY_SIZE(choice_chars); i++)
|
|
|
|
+ if (tolower(choice) == choice_chars[i])
|
|
|
|
+ return i;
|
|
|
|
+
|
|
|
|
+ return -1;
|
|
|
|
+}
|
2022-08-07 10:06:56 +00:00
|
|
|
+
|
|
|
|
+int get_choice_char(int index, char *result)
|
|
|
|
+{
|
|
|
|
+ if (index < ARRAY_SIZE(choice_chars))
|
|
|
|
+ *result = choice_chars[index];
|
|
|
|
+ else
|
|
|
|
+ return -1;
|
|
|
|
+ return 0;
|
|
|
|
+}
|
2021-02-20 13:04:38 +00:00
|
|
|
+
|
2022-07-11 10:02:49 +00:00
|
|
|
/*
|
|
|
|
* An iterator function for menu items. callback will be called for each item
|
|
|
|
* in m, with m, a pointer to the item, and extra being passed to callback. If
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -437,7 +464,7 @@ int menu_destroy(struct menu *m)
|
2021-02-20 13:04:38 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 23:21:22 +00:00
|
|
|
enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
|
|
|
|
- struct cli_ch_state *cch)
|
|
|
|
+ struct cli_ch_state *cch, int *choice)
|
2021-02-20 13:04:38 +00:00
|
|
|
{
|
2023-04-11 23:21:22 +00:00
|
|
|
enum bootmenu_key key = BKEY_NONE;
|
2021-02-20 13:04:38 +00:00
|
|
|
int i, c;
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -472,6 +499,19 @@ enum bootmenu_key bootmenu_autoboot_loop
|
2021-02-20 13:04:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
2023-04-11 23:21:22 +00:00
|
|
|
key = BKEY_NONE;
|
|
|
|
+ if (cch->esc_len || !choice)
|
2021-02-20 13:04:38 +00:00
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ *choice = find_choice(c);
|
|
|
|
+ if ((*choice >= 0 &&
|
|
|
|
+ *choice < menu->count - 1)) {
|
2023-04-11 23:21:22 +00:00
|
|
|
+ key = BKEY_CHOICE;
|
2021-02-20 13:04:38 +00:00
|
|
|
+ } else if (c == '0') {
|
|
|
|
+ *choice = menu->count - 1;
|
2023-04-11 23:21:22 +00:00
|
|
|
+ key = BKEY_CHOICE;
|
2021-02-20 13:04:38 +00:00
|
|
|
+ } else {
|
2023-04-11 23:21:22 +00:00
|
|
|
+ key = BKEY_NONE;
|
2021-02-20 13:04:38 +00:00
|
|
|
+ }
|
|
|
|
break;
|
|
|
|
}
|
2023-04-11 23:21:22 +00:00
|
|
|
break;
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -492,7 +532,8 @@ enum bootmenu_key bootmenu_autoboot_loop
|
2023-04-11 23:21:22 +00:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
-enum bootmenu_key bootmenu_conv_key(int ichar)
|
|
|
|
+enum bootmenu_key bootmenu_conv_key(struct bootmenu_data *menu, int ichar,
|
|
|
|
+ int *choice)
|
|
|
|
{
|
|
|
|
enum bootmenu_key key;
|
2021-02-20 13:04:38 +00:00
|
|
|
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -524,6 +565,20 @@ enum bootmenu_key bootmenu_conv_key(int
|
2023-04-11 23:21:22 +00:00
|
|
|
case ' ':
|
|
|
|
key = BKEY_SPACE;
|
|
|
|
break;
|
|
|
|
+ case '0' ... '9':
|
|
|
|
+ case 'a' ... 'z':
|
|
|
|
+ if (choice && menu) {
|
|
|
|
+ *choice = find_choice(ichar);
|
|
|
|
+ if ((*choice >= 0 && *choice < menu->count - 1)) {
|
|
|
|
+ key = BKEY_CHOICE;
|
|
|
|
+ break;
|
|
|
|
+ } else if (ichar == '0') {
|
|
|
|
+ *choice = menu->count - 1;
|
|
|
|
+ key = BKEY_CHOICE;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ fallthrough;
|
|
|
|
default:
|
|
|
|
key = BKEY_NONE;
|
|
|
|
break;
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -533,11 +588,17 @@ enum bootmenu_key bootmenu_conv_key(int
|
2021-02-20 13:04:38 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 23:21:22 +00:00
|
|
|
enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
|
|
|
|
- struct cli_ch_state *cch)
|
2024-10-31 21:08:10 +00:00
|
|
|
+ struct cli_ch_state *cch,
|
|
|
|
+ int *choice)
|
2021-02-20 13:04:38 +00:00
|
|
|
{
|
2023-04-11 23:21:22 +00:00
|
|
|
enum bootmenu_key key;
|
2024-10-31 21:08:10 +00:00
|
|
|
int c, errchar = 0;
|
2021-02-20 13:04:38 +00:00
|
|
|
|
|
|
|
+ if (menu->last_choiced) {
|
|
|
|
+ menu->last_choiced = false;
|
2023-04-11 23:21:22 +00:00
|
|
|
+ return BKEY_SELECT;
|
2021-02-20 13:04:38 +00:00
|
|
|
+ }
|
|
|
|
+
|
2023-04-11 23:21:22 +00:00
|
|
|
c = cli_ch_process(cch, 0);
|
|
|
|
if (!c) {
|
|
|
|
while (!c && !tstc()) {
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -552,7 +613,7 @@ enum bootmenu_key bootmenu_loop(struct b
|
2021-02-20 13:04:38 +00:00
|
|
|
}
|
2023-04-11 23:21:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- key = bootmenu_conv_key(c);
|
|
|
|
+ key = bootmenu_conv_key(menu, c, choice);
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
2022-07-11 10:02:49 +00:00
|
|
|
--- a/include/menu.h
|
|
|
|
+++ b/include/menu.h
|
2023-01-13 03:13:24 +00:00
|
|
|
@@ -6,6 +6,8 @@
|
2022-08-07 10:06:56 +00:00
|
|
|
#ifndef __MENU_H__
|
|
|
|
#define __MENU_H__
|
|
|
|
|
|
|
|
+#include <linux/ctype.h>
|
|
|
|
+
|
2023-04-11 23:21:22 +00:00
|
|
|
struct cli_ch_state;
|
2022-08-07 10:06:56 +00:00
|
|
|
struct menu;
|
|
|
|
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -20,6 +22,8 @@ int menu_get_choice(struct menu *m, void
|
2022-08-07 10:06:56 +00:00
|
|
|
int menu_item_add(struct menu *m, char *item_key, void *item_data);
|
|
|
|
int menu_destroy(struct menu *m);
|
|
|
|
int menu_default_choice(struct menu *m, void **choice);
|
|
|
|
+/* Add KEY_CHOICE support */
|
|
|
|
+int get_choice_char(int index, char *result);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* menu_show() Show a boot menu
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -43,6 +47,7 @@ struct bootmenu_data {
|
|
|
|
int last_active; /* last active menu entry */
|
2022-07-11 10:02:49 +00:00
|
|
|
int count; /* total count of menu entries */
|
|
|
|
struct bootmenu_entry *first; /* first menu entry */
|
|
|
|
+ bool last_choiced;
|
|
|
|
};
|
2021-02-20 13:04:38 +00:00
|
|
|
|
2023-04-11 23:21:22 +00:00
|
|
|
/** enum bootmenu_key - keys that can be returned by the bootmenu */
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -53,6 +58,7 @@ enum bootmenu_key {
|
2023-12-13 05:37:20 +00:00
|
|
|
BKEY_SELECT,
|
|
|
|
BKEY_QUIT,
|
2023-04-11 23:21:22 +00:00
|
|
|
BKEY_SAVE,
|
|
|
|
+ BKEY_CHOICE,
|
|
|
|
|
2023-12-13 05:37:20 +00:00
|
|
|
/* 'extra' keys, which are used by menus but not cedit */
|
|
|
|
BKEY_PLUS,
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -83,7 +89,7 @@ enum bootmenu_key {
|
2023-04-11 23:21:22 +00:00
|
|
|
* anything else: KEY_NONE
|
|
|
|
*/
|
|
|
|
enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
|
|
|
|
- struct cli_ch_state *cch);
|
|
|
|
+ struct cli_ch_state *cch, int *choice);
|
2021-02-20 13:04:38 +00:00
|
|
|
|
2023-04-11 23:21:22 +00:00
|
|
|
/**
|
|
|
|
* bootmenu_loop() - handle waiting for a keypress when autoboot is disabled
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -109,7 +115,7 @@ enum bootmenu_key bootmenu_autoboot_loop
|
2023-04-11 23:21:22 +00:00
|
|
|
* Space: BKEY_SPACE
|
|
|
|
*/
|
|
|
|
enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
|
|
|
|
- struct cli_ch_state *cch);
|
|
|
|
+ struct cli_ch_state *cch, int *choice);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bootmenu_conv_key() - Convert a U-Boot keypress into a menu key
|
2024-10-31 21:08:10 +00:00
|
|
|
@@ -117,6 +123,7 @@ enum bootmenu_key bootmenu_loop(struct b
|
2023-04-11 23:21:22 +00:00
|
|
|
* @ichar: Keypress to convert (ASCII, including control characters)
|
|
|
|
* Returns: Menu key that corresponds to @ichar, or BKEY_NONE if none
|
|
|
|
*/
|
|
|
|
-enum bootmenu_key bootmenu_conv_key(int ichar);
|
|
|
|
+enum bootmenu_key bootmenu_conv_key(struct bootmenu_data *menu, int ichar,
|
|
|
|
+ int *choice);
|
2023-01-13 03:13:24 +00:00
|
|
|
|
2022-07-11 10:02:49 +00:00
|
|
|
#endif /* __MENU_H__ */
|
2023-04-11 23:21:22 +00:00
|
|
|
--- a/cmd/eficonfig.c
|
|
|
|
+++ b/cmd/eficonfig.c
|
|
|
|
@@ -239,7 +239,7 @@ char *eficonfig_choice_entry(void *data)
|
|
|
|
cli_ch_init(cch);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
- key = bootmenu_loop((struct bootmenu_data *)efi_menu, cch);
|
|
|
|
+ key = bootmenu_loop((struct bootmenu_data *)efi_menu, cch, NULL);
|
|
|
|
|
|
|
|
switch (key) {
|
|
|
|
case BKEY_UP:
|
2024-10-07 17:31:58 +00:00
|
|
|
@@ -1881,7 +1881,7 @@ char *eficonfig_choice_change_boot_order
|
2023-04-11 23:21:22 +00:00
|
|
|
|
|
|
|
cli_ch_init(cch);
|
|
|
|
while (1) {
|
|
|
|
- key = bootmenu_loop(NULL, cch);
|
|
|
|
+ key = bootmenu_loop(NULL, cch, NULL);
|
|
|
|
|
|
|
|
switch (key) {
|
|
|
|
case BKEY_PLUS:
|
2023-08-25 02:58:33 +00:00
|
|
|
--- a/boot/bootflow_menu.c
|
|
|
|
+++ b/boot/bootflow_menu.c
|
2024-10-07 17:31:58 +00:00
|
|
|
@@ -240,7 +240,7 @@ int bootflow_menu_run(struct bootstd_pri
|
2023-08-25 02:58:33 +00:00
|
|
|
|
|
|
|
key = 0;
|
|
|
|
if (ichar) {
|
|
|
|
- key = bootmenu_conv_key(ichar);
|
|
|
|
+ key = bootmenu_conv_key(NULL, ichar, NULL);
|
|
|
|
if (key == BKEY_NONE)
|
|
|
|
key = ichar;
|
|
|
|
}
|