++menu->active;
/* no menu key selected, regenerate menu */
return NULL;
+ case BKEY_SHORTCUT:
+ /* invalid shortcut, regenerate menu */
+ if (cch->shortcut_key >= menu->count - 1)
+ return NULL;
+ /* shortcut_key value for Exit is is -1 */
+ menu->active = cch->shortcut_key < 0 ? menu->count - 1 :
+ cch->shortcut_key;
+ fallthrough;
case BKEY_SELECT:
iter = menu->first;
for (i = 0; i < menu->active; ++i)
free(menu);
}
+static char bootmenu_entry_shortcut_key(int index)
+{
+ switch (index) {
+ /* 1-9 shortcut key (0 reserved) */
+ case 0 ... 8:
+ return '1' + index;
+ /* a-z shortcut key */
+ case 9 ... 34:
+ return 'a' + index - 9;
+ /* We support shortcut for up to 34 options (0 reserved) */
+ default:
+ return -ENOENT;
+ }
+}
+
/**
* prepare_bootmenu_entry() - generate the bootmenu_xx entries
*
struct bootmenu_entry *iter = *current;
while ((option = bootmenu_getoption(i))) {
+ char shortcut_key;
+ int len;
/* bootmenu_[num] format is "[title]=[commands]" */
sep = strchr(option, '=');
if (!entry)
return -ENOMEM;
- entry->title = strndup(option, sep - option);
+ /* Add shotcut key option: %c. %s\0 */
+ len = sep - option + 4;
+
+ entry->title = malloc(len);
if (!entry->title) {
free(entry);
return -ENOMEM;
}
+ shortcut_key = bootmenu_entry_shortcut_key(i);
+ /* Use emtpy space if entry doesn't support shortcut key */
+ snprintf(entry->title, len, "%c%c %s",
+ shortcut_key > 0 ? shortcut_key : ' ',
+ shortcut_key > 0 ? '.' : ' ',
+ option);
+
entry->command = strdup(sep + 1);
if (!entry->command) {
free(entry->title);
/* Add Quit entry if exiting bootmenu is disabled */
if (!IS_ENABLED(CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE))
- entry->title = strdup("Exit");
+ entry->title = strdup("0. Exit");
else
- entry->title = strdup("Quit");
+ entry->title = strdup("0. Quit");
if (!entry->title) {
free(entry);
#include <cli.h>
#include <malloc.h>
#include <errno.h>
+#include <linux/ctype.h>
#include <linux/delay.h>
#include <linux/list.h>
#include <watchdog.h>
return 1;
}
+static int bootmenu_conv_shortcut_key(struct bootmenu_data *menu, int ichar)
+{
+ int shortcut_key;
+
+ ichar = tolower(ichar);
+ switch (ichar) {
+ /* a-z for bootmenu entry > 9 */
+ case 'a' ... 'z':
+ shortcut_key = ichar - 'a' + 9;
+ break;
+ /* 1-9 for bootmenu entry <= 9 */
+ case '1' ... '9':
+ shortcut_key = ichar - '1';
+ break;
+ /* Reserve 0 for last option (aka Exit) */
+ case '0':
+ default:
+ return -1;
+ }
+
+ return shortcut_key;
+}
+
enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
struct cli_ch_state *cch)
{
int i, c;
while (menu->delay > 0) {
+ int ichar;
+
if (ansi)
printf(ANSI_CURSOR_POSITION, menu->count + 5, 3);
printf("Hit any key to stop autoboot: %d ", menu->delay);
for (i = 0; i < 100; ++i) {
- int ichar;
-
if (!tstc()) {
schedule();
mdelay(10);
case 0x3: /* ^C */
key = BKEY_QUIT;
break;
+ case 'A' ... 'Z':
+ case 'a' ... 'z':
+ case '0' ... '9':
+ key = BKEY_SHORTCUT;
+ break;
default:
key = BKEY_NONE;
break;
break;
}
+ if (key == BKEY_SHORTCUT)
+ cch->shortcut_key = bootmenu_conv_shortcut_key(menu, ichar);
+
if (menu->delay < 0)
break;
case ' ':
key = BKEY_SPACE;
break;
+ case 'A' ... 'Z':
+ case 'a' ... 'z':
+ case '0' ... '9':
+ key = BKEY_SHORTCUT;
+ break;
default:
key = BKEY_NONE;
break;
key = bootmenu_conv_key(c);
+ if (key == BKEY_SHORTCUT)
+ cch->shortcut_key = bootmenu_conv_shortcut_key(menu, c);
+
return key;
}