swig has been installed on the buildbots a while a ago and Petr Štetiar got a fix for the pylibfdt error. Use that and re-enable the builds for mt7620 and mt7621. Refresh patches while at it. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
		
			
				
	
	
		
			219 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			219 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
From afea25576fc92d562b248b783cf03564eb4521da Mon Sep 17 00:00:00 2001
 | 
						|
From: Weijie Gao <weijie.gao@mediatek.com>
 | 
						|
Date: Tue, 19 Jan 2021 10:58:48 +0800
 | 
						|
Subject: [PATCH 12/12] cmd: bootmenu: add ability to select item by shortkey
 | 
						|
 | 
						|
Add ability to use shortkey to select item for bootmenu command
 | 
						|
 | 
						|
Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
 | 
						|
---
 | 
						|
 cmd/bootmenu.c | 77 +++++++++++++++++++++++++++++++++++++++++++++-----
 | 
						|
 1 file changed, 70 insertions(+), 7 deletions(-)
 | 
						|
 | 
						|
--- a/cmd/bootmenu.c
 | 
						|
+++ b/cmd/bootmenu.c
 | 
						|
@@ -14,6 +14,7 @@
 | 
						|
 #include <menu.h>
 | 
						|
 #include <watchdog.h>
 | 
						|
 #include <malloc.h>
 | 
						|
+#include <linux/ctype.h>
 | 
						|
 #include <linux/delay.h>
 | 
						|
 #include <linux/string.h>
 | 
						|
 
 | 
						|
@@ -87,16 +88,17 @@ static char *bootmenu_choice_entry(void
 | 
						|
 	struct bootmenu_data *menu = data;
 | 
						|
 	struct bootmenu_entry *iter;
 | 
						|
 	enum bootmenu_key key = KEY_NONE;
 | 
						|
+	int choice = -1;
 | 
						|
 	int esc = 0;
 | 
						|
 	int i;
 | 
						|
 
 | 
						|
 	while (1) {
 | 
						|
 		if (menu->delay >= 0) {
 | 
						|
 			/* Autoboot was not stopped */
 | 
						|
-			bootmenu_autoboot_loop(menu, &key, &esc);
 | 
						|
+			bootmenu_autoboot_loop(menu, &key, &esc, &choice);
 | 
						|
 		} else {
 | 
						|
 			/* Some key was pressed, so autoboot was stopped */
 | 
						|
-			bootmenu_loop(menu, &key, &esc);
 | 
						|
+			bootmenu_loop(menu, &key, &esc, &choice);
 | 
						|
 		}
 | 
						|
 
 | 
						|
 		switch (key) {
 | 
						|
@@ -110,6 +112,12 @@ static char *bootmenu_choice_entry(void
 | 
						|
 				++menu->active;
 | 
						|
 			/* no menu key selected, regenerate menu */
 | 
						|
 			return NULL;
 | 
						|
+		case KEY_CHOICE:
 | 
						|
+			menu->active = choice;
 | 
						|
+			if (!menu->last_choiced) {
 | 
						|
+				menu->last_choiced = true;
 | 
						|
+				return NULL;
 | 
						|
+			}
 | 
						|
 		case KEY_SELECT:
 | 
						|
 			iter = menu->first;
 | 
						|
 			for (i = 0; i < menu->active; ++i)
 | 
						|
@@ -181,12 +189,19 @@ static int prepare_bootmenu_entry(struct
 | 
						|
 		if (!entry)
 | 
						|
 			return -ENOMEM;
 | 
						|
 
 | 
						|
-		entry->title = strndup(option, sep - option);
 | 
						|
+		entry->title = malloc((sep - option) + 4);
 | 
						|
 		if (!entry->title) {
 | 
						|
 			free(entry);
 | 
						|
 			return -ENOMEM;
 | 
						|
 		}
 | 
						|
 
 | 
						|
+		if (i < ARRAY_SIZE(choice_chars)) {
 | 
						|
+			sprintf(entry->title, "%c. %.*s", choice_chars[i],
 | 
						|
+				(int)(sep - option), option);
 | 
						|
+		} else {
 | 
						|
+			sprintf(entry->title, "   %.*s", (int)(sep - option), option);
 | 
						|
+		}
 | 
						|
+
 | 
						|
 		entry->command = strdup(sep + 1);
 | 
						|
 		if (!entry->command) {
 | 
						|
 			free(entry->title);
 | 
						|
@@ -331,6 +346,7 @@ static struct bootmenu_data *bootmenu_cr
 | 
						|
 	menu->delay = delay;
 | 
						|
 	menu->active = 0;
 | 
						|
 	menu->first = NULL;
 | 
						|
+	menu->last_choiced = false;
 | 
						|
 
 | 
						|
 	default_str = env_get("bootmenu_default");
 | 
						|
 	if (default_str)
 | 
						|
@@ -356,9 +372,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))
 | 
						|
-			entry->title = strdup("U-Boot console");
 | 
						|
+			entry->title = strdup("0. U-Boot console");
 | 
						|
 		else
 | 
						|
-			entry->title = strdup("Quit");
 | 
						|
+			entry->title = strdup("0. Quit");
 | 
						|
 
 | 
						|
 		if (!entry->title) {
 | 
						|
 			free(entry);
 | 
						|
--- a/common/menu.c
 | 
						|
+++ b/common/menu.c
 | 
						|
@@ -9,6 +9,7 @@
 | 
						|
 #include <cli.h>
 | 
						|
 #include <malloc.h>
 | 
						|
 #include <errno.h>
 | 
						|
+#include <linux/ctype.h>
 | 
						|
 #include <linux/delay.h>
 | 
						|
 #include <linux/list.h>
 | 
						|
 #include <watchdog.h>
 | 
						|
@@ -47,6 +48,17 @@ struct menu {
 | 
						|
 	int item_cnt;
 | 
						|
 };
 | 
						|
 
 | 
						|
+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;
 | 
						|
+}
 | 
						|
+
 | 
						|
 /*
 | 
						|
  * 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 +438,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)
 | 
						|
 {
 | 
						|
 	int i, c;
 | 
						|
 
 | 
						|
@@ -456,6 +468,19 @@ void bootmenu_autoboot_loop(struct bootm
 | 
						|
 				break;
 | 
						|
 			default:
 | 
						|
 				*key = KEY_NONE;
 | 
						|
+				if (*esc)
 | 
						|
+					break;
 | 
						|
+
 | 
						|
+				*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;
 | 
						|
+				} else {
 | 
						|
+					*key = KEY_NONE;
 | 
						|
+				}
 | 
						|
 				break;
 | 
						|
 			}
 | 
						|
 
 | 
						|
@@ -475,10 +500,16 @@ void bootmenu_autoboot_loop(struct bootm
 | 
						|
 }
 | 
						|
 
 | 
						|
 void bootmenu_loop(struct bootmenu_data *menu,
 | 
						|
-		   enum bootmenu_key *key, int *esc)
 | 
						|
+		   enum bootmenu_key *key, int *esc, int *choice)
 | 
						|
 {
 | 
						|
 	int c;
 | 
						|
 
 | 
						|
+	if (menu->last_choiced) {
 | 
						|
+		menu->last_choiced = false;
 | 
						|
+		*key = KEY_SELECT;
 | 
						|
+		return;
 | 
						|
+	}
 | 
						|
+
 | 
						|
 	if (*esc == 1) {
 | 
						|
 		if (tstc()) {
 | 
						|
 			c = getchar();
 | 
						|
@@ -504,6 +535,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;
 | 
						|
+			}
 | 
						|
 		}
 | 
						|
 		break;
 | 
						|
 	case 1:
 | 
						|
--- a/include/menu.h
 | 
						|
+++ b/include/menu.h
 | 
						|
@@ -40,6 +40,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 {
 | 
						|
@@ -48,11 +49,19 @@ enum bootmenu_key {
 | 
						|
 	KEY_DOWN,
 | 
						|
 	KEY_SELECT,
 | 
						|
 	KEY_QUIT,
 | 
						|
+	KEY_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);
 | 
						|
+
 | 
						|
+static 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'
 | 
						|
+};
 | 
						|
 
 | 
						|
 #endif /* __MENU_H__ */
 |