diff options
author | Tom Rini <trini@konsulko.com> | 2023-01-17 08:55:40 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-01-17 08:55:40 -0500 |
commit | 5b958dea5c678dbdb2aeb6ac3c0c8cc8dfea065c (patch) | |
tree | 172424111d1a39640cf5245eefd080fae3b5fb27 /common/menu.c | |
parent | 6d03688e75041a7bae4d33815de28da781c37dd6 (diff) | |
parent | b5c8fea7b830c0304051237ad1501431a958b0e6 (diff) |
Merge branch '2022-01-16-bootstd-updates'
To quote the author:
So far standard boot lacks a boot menu, although it is possible to create
a rudimentary one using the existing 'bootmenu' command.
Even then, this text-based menu offer only basic functionality and does
not take full advantage of the displays which are common on many devices.
This series provides a 'bootflow menu' command which allows the user to
select from the available bootflows. An attempt is made to show the name
of the available operating systems, by reading more information into the
bootflow. A logo can be read also, where supported, so that this can be
presented to the user when an option is highlighted.
Full use is made of TrueType fonts, if enabled. For cases where only a
serial console is available, it falls back to a simple text-based menu.
All of this is implementing using a new 'expo' construct, a collection of
scenes (like menu screens) which can be navigated by the user to view
information and select options. This is fairly general and should be able
to cope with a wider array of use cases, with less hacking of the menu
code, such as is currently needed for CMD_BOOTEFI_BOOTMGR.
Of course it would be possible to enhance the existing menu rather than
creating a new setup. Instead it seems better to make the existing menu
use expo, if code space permits. It avoids the event-loop problem and
should be more extensible, given its loosely coupled components and use of
IDs instead of pointers. Further motivation is provided in the
documentation.
For now the CLI keypress-decoding code is split out to be used by the new
menu. The key codes defined by menu.h are reused also.
This is of course just a starting point. Some ideas for future work are
included in the documentation.
Diffstat (limited to 'common/menu.c')
-rw-r--r-- | common/menu.c | 157 |
1 files changed, 71 insertions, 86 deletions
diff --git a/common/menu.c b/common/menu.c index 8fe00965c0..cdcdbb2a18 100644 --- a/common/menu.c +++ b/common/menu.c @@ -15,6 +15,8 @@ #include "menu.h" +#define ansi 0 + /* * Internally, each item in a menu is represented by a struct menu_item. * @@ -425,15 +427,19 @@ int menu_destroy(struct menu *m) return 1; } -void bootmenu_autoboot_loop(struct bootmenu_data *menu, - enum bootmenu_key *key, int *esc) +enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, + struct cli_ch_state *cch) { + enum bootmenu_key key = BKEY_NONE; int i, c; while (menu->delay > 0) { - printf(ANSI_CURSOR_POSITION, menu->count + 5, 3); + 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); @@ -443,22 +449,22 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu, menu->delay = -1; c = getchar(); - switch (c) { - case '\e': - *esc = 1; - *key = KEY_NONE; + ichar = cli_ch_process(cch, c); + + switch (ichar) { + case '\0': + key = BKEY_NONE; break; - case '\r': - *key = KEY_SELECT; + case '\n': + key = BKEY_SELECT; break; case 0x3: /* ^C */ - *key = KEY_QUIT; + key = BKEY_QUIT; break; default: - *key = KEY_NONE; + key = BKEY_NONE; break; } - break; } @@ -468,93 +474,72 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu, --menu->delay; } - printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1); + if (ansi) + printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1); if (menu->delay == 0) - *key = KEY_SELECT; + key = BKEY_SELECT; + + return key; } -void bootmenu_loop(struct bootmenu_data *menu, - enum bootmenu_key *key, int *esc) +enum bootmenu_key bootmenu_conv_key(int ichar) { - int c; - - if (*esc == 1) { - if (tstc()) { - c = getchar(); - } else { - schedule(); - mdelay(10); - if (tstc()) - c = getchar(); - else - c = '\e'; - } - } else { - while (!tstc()) { - schedule(); - mdelay(10); - } - c = getchar(); - } + enum bootmenu_key key; - switch (*esc) { - case 0: - /* First char of ANSI escape sequence '\e' */ - if (c == '\e') { - *esc = 1; - *key = KEY_NONE; - } + switch (ichar) { + case '\n': + /* enter key was pressed */ + key = BKEY_SELECT; break; - case 1: - /* Second char of ANSI '[' */ - if (c == '[') { - *esc = 2; - *key = KEY_NONE; - } else { - /* Alone ESC key was pressed */ - *key = KEY_QUIT; - *esc = (c == '\e') ? 1 : 0; - } + case CTL_CH('c'): + case '\e': + /* ^C was pressed */ + key = BKEY_QUIT; break; - case 2: - case 3: - /* Third char of ANSI (number '1') - optional */ - if (*esc == 2 && c == '1') { - *esc = 3; - *key = KEY_NONE; - break; - } - - *esc = 0; - - /* ANSI 'A' - key up was pressed */ - if (c == 'A') - *key = KEY_UP; - /* ANSI 'B' - key down was pressed */ - else if (c == 'B') - *key = KEY_DOWN; - /* other key was pressed */ - else - *key = KEY_NONE; - + case CTL_CH('p'): + key = BKEY_UP; + break; + case CTL_CH('n'): + key = BKEY_DOWN; + break; + case '+': + key = BKEY_PLUS; + break; + case '-': + key = BKEY_MINUS; + break; + case ' ': + key = BKEY_SPACE; + break; + default: + key = BKEY_NONE; break; } - /* enter key was pressed */ - if (c == '\r') - *key = KEY_SELECT; + return key; +} - /* ^C was pressed */ - if (c == 0x3) - *key = KEY_QUIT; +enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, + struct cli_ch_state *cch) +{ + enum bootmenu_key key; + int c; - if (c == '+') - *key = KEY_PLUS; + c = cli_ch_process(cch, 0); + if (!c) { + while (!c && !tstc()) { + schedule(); + mdelay(10); + c = cli_ch_process(cch, -ETIMEDOUT); + } + if (!c) { + c = getchar(); + c = cli_ch_process(cch, c); + } + } - if (c == '-') - *key = KEY_MINUS; + key = bootmenu_conv_key(c); - if (c == ' ') - *key = KEY_SPACE; + return key; } |