|
@@ -14,40 +14,41 @@ Signed-off-by: Weijie Gao <[email protected]>
|
|
|
|
|
|
--- a/cmd/bootmenu.c
|
|
|
+++ b/cmd/bootmenu.c
|
|
|
-@@ -87,16 +87,17 @@ static char *bootmenu_choice_entry(void
|
|
|
+@@ -89,6 +89,7 @@ static char *bootmenu_choice_entry(void
|
|
|
struct bootmenu_data *menu = data;
|
|
|
struct bootmenu_entry *iter;
|
|
|
- enum bootmenu_key key = KEY_NONE;
|
|
|
+ enum bootmenu_key key = BKEY_NONE;
|
|
|
+ int choice = -1;
|
|
|
- int esc = 0;
|
|
|
int i;
|
|
|
|
|
|
+ cli_ch_init(cch);
|
|
|
+@@ -96,10 +97,10 @@ static char *bootmenu_choice_entry(void
|
|
|
while (1) {
|
|
|
if (menu->delay >= 0) {
|
|
|
/* Autoboot was not stopped */
|
|
|
-- bootmenu_autoboot_loop(menu, &key, &esc);
|
|
|
-+ bootmenu_autoboot_loop(menu, &key, &esc, &choice);
|
|
|
+- key = bootmenu_autoboot_loop(menu, cch);
|
|
|
++ key = bootmenu_autoboot_loop(menu, cch, &choice);
|
|
|
} else {
|
|
|
/* Some key was pressed, so autoboot was stopped */
|
|
|
-- bootmenu_loop(menu, &key, &esc);
|
|
|
-+ bootmenu_loop(menu, &key, &esc, &choice);
|
|
|
+- key = bootmenu_loop(menu, cch);
|
|
|
++ key = bootmenu_loop(menu, cch, &choice);
|
|
|
}
|
|
|
|
|
|
switch (key) {
|
|
|
-@@ -110,6 +111,12 @@ static char *bootmenu_choice_entry(void
|
|
|
+@@ -113,6 +114,12 @@ static char *bootmenu_choice_entry(void
|
|
|
++menu->active;
|
|
|
/* no menu key selected, regenerate menu */
|
|
|
return NULL;
|
|
|
-+ case KEY_CHOICE:
|
|
|
++ case BKEY_CHOICE:
|
|
|
+ menu->active = choice;
|
|
|
+ if (!menu->last_choiced) {
|
|
|
+ menu->last_choiced = true;
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
- case KEY_SELECT:
|
|
|
+ case BKEY_SELECT:
|
|
|
iter = menu->first;
|
|
|
for (i = 0; i < menu->active; ++i)
|
|
|
-@@ -167,6 +174,9 @@ static int prepare_bootmenu_entry(struct
|
|
|
+@@ -170,6 +177,9 @@ static int prepare_bootmenu_entry(struct
|
|
|
unsigned short int i = *index;
|
|
|
struct bootmenu_entry *entry = NULL;
|
|
|
struct bootmenu_entry *iter = *current;
|
|
@@ -57,7 +58,7 @@ Signed-off-by: Weijie Gao <[email protected]>
|
|
|
|
|
|
while ((option = bootmenu_getoption(i))) {
|
|
|
|
|
|
-@@ -181,11 +191,24 @@ static int prepare_bootmenu_entry(struct
|
|
|
+@@ -184,11 +194,24 @@ static int prepare_bootmenu_entry(struct
|
|
|
if (!entry)
|
|
|
return -ENOMEM;
|
|
|
|
|
@@ -83,7 +84,7 @@ Signed-off-by: Weijie Gao <[email protected]>
|
|
|
|
|
|
entry->command = strdup(sep + 1);
|
|
|
if (!entry->command) {
|
|
|
-@@ -331,6 +354,7 @@ static struct bootmenu_data *bootmenu_cr
|
|
|
+@@ -334,6 +357,7 @@ static struct bootmenu_data *bootmenu_cr
|
|
|
menu->delay = delay;
|
|
|
menu->active = 0;
|
|
|
menu->first = NULL;
|
|
@@ -91,7 +92,7 @@ Signed-off-by: Weijie Gao <[email protected]>
|
|
|
|
|
|
default_str = env_get("bootmenu_default");
|
|
|
if (default_str)
|
|
|
-@@ -366,9 +390,9 @@ static struct bootmenu_data *bootmenu_cr
|
|
|
+@@ -369,9 +393,9 @@ static struct bootmenu_data *bootmenu_cr
|
|
|
|
|
|
/* Add Quit entry if entering U-Boot console is disabled */
|
|
|
if (!IS_ENABLED(CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE))
|
|
@@ -105,7 +106,7 @@ Signed-off-by: Weijie Gao <[email protected]>
|
|
|
free(entry);
|
|
|
--- a/common/menu.c
|
|
|
+++ b/common/menu.c
|
|
|
-@@ -47,6 +47,33 @@ struct menu {
|
|
|
+@@ -49,6 +49,33 @@ struct menu {
|
|
|
int item_cnt;
|
|
|
};
|
|
|
|
|
@@ -139,68 +140,93 @@ Signed-off-by: Weijie Gao <[email protected]>
|
|
|
/*
|
|
|
* 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
|
|
|
-@@ -426,7 +453,7 @@ int menu_destroy(struct menu *m)
|
|
|
+@@ -428,7 +455,7 @@ int menu_destroy(struct menu *m)
|
|
|
}
|
|
|
|
|
|
- void bootmenu_autoboot_loop(struct bootmenu_data *menu,
|
|
|
-- enum bootmenu_key *key, int *esc)
|
|
|
-+ enum bootmenu_key *key, int *esc, int *choice)
|
|
|
+ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
|
|
|
+- struct cli_ch_state *cch)
|
|
|
++ struct cli_ch_state *cch, int *choice)
|
|
|
{
|
|
|
+ enum bootmenu_key key = BKEY_NONE;
|
|
|
int i, c;
|
|
|
-
|
|
|
-@@ -456,6 +483,19 @@ void bootmenu_autoboot_loop(struct bootm
|
|
|
+@@ -463,6 +490,19 @@ enum bootmenu_key bootmenu_autoboot_loop
|
|
|
break;
|
|
|
default:
|
|
|
- *key = KEY_NONE;
|
|
|
-+ if (*esc)
|
|
|
+ key = BKEY_NONE;
|
|
|
++ if (cch->esc_len || !choice)
|
|
|
+ break;
|
|
|
+
|
|
|
+ *choice = find_choice(c);
|
|
|
+ if ((*choice >= 0 &&
|
|
|
+ *choice < menu->count - 1)) {
|
|
|
-+ *key = KEY_CHOICE;
|
|
|
++ key = BKEY_CHOICE;
|
|
|
+ } else if (c == '0') {
|
|
|
+ *choice = menu->count - 1;
|
|
|
-+ *key = KEY_CHOICE;
|
|
|
++ key = BKEY_CHOICE;
|
|
|
+ } else {
|
|
|
-+ *key = KEY_NONE;
|
|
|
++ key = BKEY_NONE;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
+ break;
|
|
|
+@@ -483,7 +523,8 @@ enum bootmenu_key bootmenu_autoboot_loop
|
|
|
+ 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;
|
|
|
|
|
|
-@@ -475,10 +515,16 @@ void bootmenu_autoboot_loop(struct bootm
|
|
|
+@@ -515,6 +556,20 @@ enum bootmenu_key bootmenu_conv_key(int
|
|
|
+ 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;
|
|
|
+@@ -524,11 +579,16 @@ enum bootmenu_key bootmenu_conv_key(int
|
|
|
}
|
|
|
|
|
|
- void bootmenu_loop(struct bootmenu_data *menu,
|
|
|
-- enum bootmenu_key *key, int *esc)
|
|
|
-+ enum bootmenu_key *key, int *esc, int *choice)
|
|
|
+ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
|
|
|
+- struct cli_ch_state *cch)
|
|
|
++ struct cli_ch_state *cch, int *choice)
|
|
|
{
|
|
|
+ enum bootmenu_key key;
|
|
|
int c;
|
|
|
|
|
|
+ if (menu->last_choiced) {
|
|
|
+ menu->last_choiced = false;
|
|
|
-+ *key = KEY_SELECT;
|
|
|
-+ return;
|
|
|
++ return BKEY_SELECT;
|
|
|
+ }
|
|
|
+
|
|
|
- if (*esc == 1) {
|
|
|
- if (tstc()) {
|
|
|
- c = getchar();
|
|
|
-@@ -504,6 +550,14 @@ void bootmenu_loop(struct bootmenu_data
|
|
|
- if (c == '\e') {
|
|
|
- *esc = 1;
|
|
|
- *key = KEY_NONE;
|
|
|
-+ } else {
|
|
|
-+ *choice = find_choice(c);
|
|
|
-+ if ((*choice >= 0 && *choice < menu->count - 1)) {
|
|
|
-+ *key = KEY_CHOICE;
|
|
|
-+ } else if (c == '0') {
|
|
|
-+ *choice = menu->count - 1;
|
|
|
-+ *key = KEY_CHOICE;
|
|
|
-+ }
|
|
|
+ c = cli_ch_process(cch, 0);
|
|
|
+ if (!c) {
|
|
|
+ while (!c && !tstc()) {
|
|
|
+@@ -542,7 +602,7 @@ enum bootmenu_key bootmenu_loop(struct b
|
|
|
}
|
|
|
- break;
|
|
|
- case 1:
|
|
|
+ }
|
|
|
+
|
|
|
+- key = bootmenu_conv_key(c);
|
|
|
++ key = bootmenu_conv_key(menu, c, choice);
|
|
|
+
|
|
|
+ return key;
|
|
|
+ }
|
|
|
--- a/include/menu.h
|
|
|
+++ b/include/menu.h
|
|
|
@@ -6,6 +6,8 @@
|
|
@@ -209,10 +235,10 @@ Signed-off-by: Weijie Gao <[email protected]>
|
|
|
|
|
|
+#include <linux/ctype.h>
|
|
|
+
|
|
|
+ struct cli_ch_state;
|
|
|
struct menu;
|
|
|
|
|
|
- struct menu *menu_create(char *title, int timeout, int prompt,
|
|
|
-@@ -18,6 +20,8 @@ int menu_get_choice(struct menu *m, void
|
|
|
+@@ -19,6 +21,8 @@ int menu_get_choice(struct menu *m, void
|
|
|
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);
|
|
@@ -221,26 +247,66 @@ Signed-off-by: Weijie Gao <[email protected]>
|
|
|
|
|
|
/**
|
|
|
* menu_show() Show a boot menu
|
|
|
-@@ -40,6 +44,7 @@ struct bootmenu_data {
|
|
|
+@@ -41,6 +45,7 @@ struct bootmenu_data {
|
|
|
int active; /* active menu entry */
|
|
|
int count; /* total count of menu entries */
|
|
|
struct bootmenu_entry *first; /* first menu entry */
|
|
|
+ bool last_choiced;
|
|
|
};
|
|
|
|
|
|
- enum bootmenu_key {
|
|
|
-@@ -51,11 +56,12 @@ enum bootmenu_key {
|
|
|
- KEY_PLUS,
|
|
|
- KEY_MINUS,
|
|
|
- KEY_SPACE,
|
|
|
-+ KEY_CHOICE,
|
|
|
+ /** enum bootmenu_key - keys that can be returned by the bootmenu */
|
|
|
+@@ -54,6 +59,7 @@ enum bootmenu_key {
|
|
|
+ BKEY_MINUS,
|
|
|
+ BKEY_SPACE,
|
|
|
+ BKEY_SAVE,
|
|
|
++ BKEY_CHOICE,
|
|
|
+
|
|
|
+ BKEY_COUNT,
|
|
|
};
|
|
|
+@@ -76,7 +82,7 @@ enum bootmenu_key {
|
|
|
+ * 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);
|
|
|
|
|
|
- void bootmenu_autoboot_loop(struct bootmenu_data *menu,
|
|
|
-- enum bootmenu_key *key, int *esc);
|
|
|
-+ enum bootmenu_key *key, int *esc, int *choice);
|
|
|
- void bootmenu_loop(struct bootmenu_data *menu,
|
|
|
-- enum bootmenu_key *key, int *esc);
|
|
|
-+ enum bootmenu_key *key, int *esc, int *choice);
|
|
|
+ /**
|
|
|
+ * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled
|
|
|
+@@ -102,7 +108,7 @@ enum bootmenu_key bootmenu_autoboot_loop
|
|
|
+ * 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
|
|
|
+@@ -110,6 +116,7 @@ enum bootmenu_key bootmenu_loop(struct b
|
|
|
+ * @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);
|
|
|
|
|
|
#endif /* __MENU_H__ */
|
|
|
+--- 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:
|
|
|
+@@ -1937,7 +1937,7 @@ char *eficonfig_choice_change_boot_order
|
|
|
+
|
|
|
+ cli_ch_init(cch);
|
|
|
+ while (1) {
|
|
|
+- key = bootmenu_loop(NULL, cch);
|
|
|
++ key = bootmenu_loop(NULL, cch, NULL);
|
|
|
+
|
|
|
+ switch (key) {
|
|
|
+ case BKEY_PLUS:
|