aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2022-05-08 11:31:48 -0400
committerTom Rini <trini@konsulko.com>2022-05-08 11:31:48 -0400
commit20cd58479f8c23cdb868fd9cd2042d59782056fc (patch)
treea74c2f99666c03e7b21bc4d7ad0b646613c2ee0b /common
parent258a57907d158d3ba54ec4e6daf0595d2f670d65 (diff)
parent4b494770577cc61c3c1a4b57ced2fc98d87957dc (diff)
downloadu-boot-20cd58479f8c23cdb868fd9cd2042d59782056fc.zip
u-boot-20cd58479f8c23cdb868fd9cd2042d59782056fc.tar.gz
u-boot-20cd58479f8c23cdb868fd9cd2042d59782056fc.tar.bz2
Merge tag 'efi-2022-07-rc3-2' of https://source.denx.de/u-boot/custodians/u-boot-efiWIP/08May2022
Pull request for efi-2022-07-rc3-2 UEFI: * Fix build errors due to - using sed with non-standard extension for regular expression - target architecture not recognized for CROSS_COMPILE=armv7a-* - CONFIG_EVENT not selected * add sha384/512 on certificate revocation Others: * factor out the user input handling in bootmenu command
Diffstat (limited to 'common')
-rw-r--r--common/menu.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/common/menu.c b/common/menu.c
index f5fc693..3e876b5 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -4,11 +4,14 @@
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
*/
+#include <ansi.h>
#include <common.h>
#include <cli.h>
#include <malloc.h>
#include <errno.h>
+#include <linux/delay.h>
#include <linux/list.h>
+#include <watchdog.h>
#include "menu.h"
@@ -421,3 +424,128 @@ int menu_destroy(struct menu *m)
return 1;
}
+
+void bootmenu_autoboot_loop(struct bootmenu_data *menu,
+ enum bootmenu_key *key, int *esc)
+{
+ int i, c;
+
+ while (menu->delay > 0) {
+ printf(ANSI_CURSOR_POSITION, menu->count + 5, 3);
+ printf("Hit any key to stop autoboot: %d ", menu->delay);
+ for (i = 0; i < 100; ++i) {
+ if (!tstc()) {
+ WATCHDOG_RESET();
+ mdelay(10);
+ continue;
+ }
+
+ menu->delay = -1;
+ c = getchar();
+
+ switch (c) {
+ case '\e':
+ *esc = 1;
+ *key = KEY_NONE;
+ break;
+ case '\r':
+ *key = KEY_SELECT;
+ break;
+ case 0x3: /* ^C */
+ *key = KEY_QUIT;
+ break;
+ default:
+ *key = KEY_NONE;
+ break;
+ }
+
+ break;
+ }
+
+ if (menu->delay < 0)
+ break;
+
+ --menu->delay;
+ }
+
+ printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1);
+
+ if (menu->delay == 0)
+ *key = KEY_SELECT;
+}
+
+void bootmenu_loop(struct bootmenu_data *menu,
+ enum bootmenu_key *key, int *esc)
+{
+ int c;
+
+ if (*esc == 1) {
+ if (tstc()) {
+ c = getchar();
+ } else {
+ WATCHDOG_RESET();
+ mdelay(10);
+ if (tstc())
+ c = getchar();
+ else
+ c = '\e';
+ }
+ } else {
+ while (!tstc()) {
+ WATCHDOG_RESET();
+ mdelay(10);
+ }
+ c = getchar();
+ }
+
+ switch (*esc) {
+ case 0:
+ /* First char of ANSI escape sequence '\e' */
+ if (c == '\e') {
+ *esc = 1;
+ *key = KEY_NONE;
+ }
+ 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;
+ }
+ 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;
+
+ break;
+ }
+
+ /* enter key was pressed */
+ if (c == '\r')
+ *key = KEY_SELECT;
+
+ /* ^C was pressed */
+ if (c == 0x3)
+ *key = KEY_QUIT;
+}