[PATCH 12/15] New command bootmenu: ANSI terminal Boot Menu su=
=3D?UTF-8?q?Pali=3D20Roh=3DC3=3DA1r?=3D
pali.rohar at gmail.com
Wed Aug 31 12:07:50 CEST 2011
pport
* Configuration is done via env variables bootmenu_delay and bootmenu_=
<num>:
bootmenu_delay=3D<delay>
bootmenu_<num>=3D"<title>: <commands>" (title and commands are sepa=
rated by first char ':')
<delay> is delay in seconds of autobooting first entry
<num> is boot menu entry, starting from zero
<title> is text shown in boot screen
<commands> are commands which will be executed when menu entry will=
be selected
* First argument of bootmenu command override bootmenu_delay env
* If env bootmenu_delay or bootmenu argument is not specified, 10 seco=
nds for delay will be used
* If delay is 0, no entry will be show on screen, screen will not be c=
leared and first entry will be called
* If delay is less then 0, no autoboot delay will be used
* Boot Menu will stop finding next menu entry if last was not defined
* Boot Menu always add menu entry "U-Boot console" at end of all entri=
es
* Example using:
setenv bootmenu_0 "First: bootm 0x82000000" # Set first menu entry=
setenv bootmenu_1 "Second: bootm 0x83000000" # Set second menu entr=
y
setenv bootmenu_2 "Reset: reset" # Set third menu entry=
bootmenu 20 # Run bootmenu with au=
toboot delay 20s
---
common/Makefile | 1 +
common/cmd_bootmenu.c | 316 ++++++++++++++++++++++++++++++++++++++=
++++++++
include/config_cmd_all.h | 1 +
3 files changed, 318 insertions(+), 0 deletions(-)
create mode 100644 common/cmd_bootmenu.c
diff --git a/common/Makefile b/common/Makefile
index d662468..d51d577 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -68,6 +68,7 @@ COBJS-$(CONFIG_CMD_SOURCE) +=3D cmd_source.o
COBJS-$(CONFIG_CMD_BDI) +=3D cmd_bdinfo.o
COBJS-$(CONFIG_CMD_BEDBUG) +=3D bedbug.o cmd_bedbug.o
COBJS-$(CONFIG_CMD_BMP) +=3D cmd_bmp.o
+COBJS-$(CONFIG_CMD_BOOTMENU) +=3D cmd_bootmenu.o
COBJS-$(CONFIG_CMD_BOOTLDR) +=3D cmd_bootldr.o
COBJS-$(CONFIG_CMD_CACHE) +=3D cmd_cache.o
COBJS-$(CONFIG_CMD_CONSOLE) +=3D cmd_console.o
diff --git a/common/cmd_bootmenu.c b/common/cmd_bootmenu.c
new file mode 100644
index 0000000..7f8e6a8
--- /dev/null
+++ b/common/cmd_bootmenu.c
@@ -0,0 +1,316 @@
+/*
+ * (C) Copyright 2011 Pali Roh=C3=A1r <pali.rohar at gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <command.h>
+#include <watchdog.h>
+#include <linux/string.h>
+
+#ifdef CONFIG_SYS_HUSH_PARSER
+#include <hush.h>
+#endif
+
+static char * get_option(int n) {
+
+=09char name[] =3D "bootmenu_\0\0";
+
+=09if ( n < 0 || n > 99 )
+=09=09return NULL;
+
+=09sprintf(name+9, "%d", n);
+
+=09return getenv(name);
+
+}
+
+static char * get_end_of_title(char * str) {
+
+=09if ( ! str )
+=09=09return NULL;
+
+=09return strchr(str, ':');
+
+}
+
+static int print_title(char * begin, char * end) {
+
+=09if ( ! begin || ! end || end < begin )
+=09=09return 1;
+
+=09while ( begin !=3D end )
+=09=09putc(*(begin++));
+
+=09return 0;
+
+}
+
+static int print_entry(int n, int reverse) {
+
+=09char * str =3D get_option(n);
+=09char * end =3D get_end_of_title(str);
+
+=09if ( ! end )
+=09=09return 1;
+
+=09printf(ANSI_CURSOR_POSITION, n+4, 1);
+
+=09if ( reverse )
+=09=09printf(ANSI_COLOR, ANSI_COLOR_ATTR_REVERSE);
+
+=09printf(" ");
+=09print_title(str, end);
+=09printf(ANSI_CLEAR_LINE_TO_END);
+
+=09if ( reverse ) {
+
+=09=09putc('\n'); //HACK: this prevent to draw black cursor by cfb_con=
sole driver
+=09=09printf(ANSI_COLOR, ANSI_COLOR_ATTR_RESET);
+
+=09}
+
+=09return 0;
+
+}
+
+static int print_menu(int active) {
+
+=09int n =3D 0;
+
+=09printf(ANSI_CURSOR_POSITION, 1, 1);
+=09printf(ANSI_CLEAR_LINE);
+=09printf(ANSI_CURSOR_POSITION, 2, 1);
+=09printf(" *** U-Boot BOOT MENU ***");
+=09printf(ANSI_CLEAR_LINE_TO_END);
+=09printf(ANSI_CURSOR_POSITION, 3, 1);
+=09printf(ANSI_CLEAR_LINE);
+
+=09while ( 1 ) {
+
+=09=09int ret =3D print_entry(n, n =3D=3D active ? 1 : 0);
+
+=09=09if ( ret =3D=3D 1 )
+=09=09=09break;
+
+=09=09++n;
+
+=09}
+
+=09printf(ANSI_CURSOR_POSITION, n+4, 1);
+
+=09if ( n =3D=3D active )
+=09=09printf(ANSI_COLOR, ANSI_COLOR_ATTR_REVERSE);
+
+=09printf(" U-Boot console");
+=09printf(ANSI_CLEAR_LINE_TO_END);
+
+=09if ( n =3D=3D active ) {
+
+=09=09putc('\n'); //HACK: this prevent to draw black cursor by cfb_con=
sole driver
+=09=09printf(ANSI_COLOR, ANSI_COLOR_ATTR_RESET);
+
+=09}
+
+=09printf(ANSI_CURSOR_POSITION, n+5, 1);
+=09printf(ANSI_CLEAR_LINE);
+=09printf(ANSI_CURSOR_POSITION, n+6, 1);
+=09printf(" Press UP/DOWN to move, ENTER to select");
+=09printf(ANSI_CLEAR_LINE_TO_END);
+=09printf(ANSI_CURSOR_POSITION, n+7, 1);
+=09printf(ANSI_CLEAR_LINE);
+
+=09return n;
+
+}
+
+int do_bootmenu(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg=
v[]) {
+
+=09int active =3D 0;
+=09int abort =3D 0;
+=09int key =3D 0;
+=09int count =3D 0;
+=09int delay =3D 10;
+=09int instant =3D 0;
+=09char * delay_str =3D NULL;
+
+=09if ( argc >=3D 2 )
+=09=09delay_str =3D argv[1];
+
+=09if ( ! delay_str )
+=09=09delay_str =3D getenv("bootmenu_delay");
+
+=09if ( delay_str )
+=09=09delay =3D (int)simple_strtol(delay_str, NULL, 10);
+
+=09if ( delay =3D=3D 0 ) {
+
+=09=09if ( get_end_of_title(get_option(0)) ) // prevent setting U-Boot=
console as first menu entry
+=09=09=09count =3D 1;
+
+=09=09instant =3D 1;
+
+=09}
+
+=09if ( delay < 0 )
+=09=09abort =3D 1;
+
+=09if ( ! instant ) {
+
+=09=09printf(ANSI_CLEAR_CONSOLE);
+=09=09printf(ANSI_CURSOR_POSITION, 1, 1);
+
+=09}
+
+=09while ( 1 ) {
+
+=09=09if ( abort || delay > 0 )
+=09=09=09count =3D print_menu(active);
+
+=09=09if ( ! abort ) {
+
+=09=09=09if ( delay > 0 )
+=09=09=09=09printf(" Hit any key to stop autoboot: %2d ", delay);
+
+=09=09=09while ( delay > 0 ) {
+
+=09=09=09=09int i;
+
+=09=09=09=09for ( i =3D 0; i < 100; ++i ) {
+
+=09=09=09=09=09if ( tstc() ) {
+
+=09=09=09=09=09=09abort =3D 1;
+=09=09=09=09=09=09key =3D getc();
+=09=09=09=09=09=09break;
+
+=09=09=09=09=09}
+
+=09=09=09=09=09WATCHDOG_RESET();
+=09=09=09=09=09udelay(10000);
+
+=09=09=09=09}
+
+=09=09=09=09if ( abort )
+=09=09=09=09=09break;
+
+=09=09=09=09--delay;
+=09=09=09=09printf("\b\b\b%2d ", delay);
+
+=09=09=09}
+
+=09=09=09if ( delay <=3D 0 )
+=09=09=09=09key =3D '\r';
+
+=09=09} else {
+
+=09=09=09while ( ! tstc() ) {
+
+=09=09=09=09WATCHDOG_RESET();
+=09=09=09=09udelay(10000);
+
+=09=09=09}
+
+=09=09=09key =3D getc();
+
+=09=09}
+
+=09=09if ( key =3D=3D 24 ) {
+
+=09=09=09if ( active > 0 )
+=09=09=09=09--active;
+
+=09=09} else if ( key =3D=3D 25 ) {
+
+=09=09=09if ( active < count )
+=09=09=09=09++active;
+
+=09=09} else if ( key =3D=3D '\r' ) {
+
+=09=09=09char * str;
+=09=09=09char * end;
+
+=09=09=09putc('\n');
+
+=09=09=09if ( ! instant ) {
+
+=09=09=09=09printf(ANSI_CLEAR_CONSOLE);
+=09=09=09=09printf(ANSI_CURSOR_POSITION, 1, 1);
+
+=09=09=09}
+
+=09=09=09WATCHDOG_RESET();
+
+=09=09=09if ( active =3D=3D count ) { // Last entry is always U-Boot c=
onsole
+
+=09=09=09=09printf("Starting U-Boot console\n\n");
+=09=09=09=09return 0;
+
+=09=09=09}
+
+=09=09=09str =3D get_option(active);
+=09=09=09end =3D get_end_of_title(str);
+
+=09=09=09if ( ! end ) {
+
+=09=09=09=09printf("Invalid Boot Menu entry %d\nStarting U-Boot consol=
e\n\n", active);
+=09=09=09=09return 0;
+
+=09=09=09}
+
+=09=09=09if ( ! end[1] ) {
+
+=09=09=09=09printf("Invalid Boot Menu entry %d: ", active);
+=09=09=09=09print_title(str, end);
+=09=09=09=09printf("\nStarting U-Boot console\n\n");
+=09=09=09=09return 0;
+
+=09=09=09}
+
+=09=09=09printf("Booting Boot Menu entry %d: ", active);
+=09=09=09print_title(str, end);
+=09=09=09printf(" ...\n\n");
+
+# ifndef CONFIG_SYS_HUSH_PARSER
+=09=09=09run_command(end+1, 0);
+# else
+=09=09=09parse_string_outer(end+1, FLAG_PARSE_SEMICOLON | FLAG_EXIT_FR=
OM_LOOP);
+# endif
+
+=09=09=09printf("\nFailed booting Boot Menu entry %d: ", active);
+=09=09=09print_title(str, end);
+=09=09=09printf("\nStarting U-Boot console\n\n");
+=09=09=09return 0;
+
+=09=09}
+
+=09}
+
+=09/* never happends */
+=09return 1;
+
+}
+
+U_BOOT_CMD(
+=09bootmenu, 2, 1, do_bootmenu,
+=09"ANSI terminal bootmenu",
+=09"[delay]\n"
+=09" - show ANSI terminal bootmenu with autoboot delay (default 10s=
)"
+);
diff --git a/include/config_cmd_all.h b/include/config_cmd_all.h
index 9716f9c..360cc10 100644
--- a/include/config_cmd_all.h
+++ b/include/config_cmd_all.h
@@ -20,6 +20,7 @@
#define CONFIG_CMD_BEDBUG=09/* Include BedBug Debugger=09*/
#define CONFIG_CMD_BMP=09=09/* BMP support=09=09=09*/
#define CONFIG_CMD_BOOTD=09/* bootd=09=09=09*/
+#define CONFIG_CMD_BOOTMENU=09/* ANSI terminal Boot Menu=09*/
#define CONFIG_CMD_BSP=09=09/* Board Specific functions=09*/
#define CONFIG_CMD_CACHE=09/* icache, dcache=09=09*/
#define CONFIG_CMD_CDP=09=09/* Cisco Discovery Protocol=09*/
--=20
1.7.4.1
--nextPart1511561.nRVgJThL9n
Content-Disposition: attachment; filename="0013-New-config-variable-CONFIG_MENU.patch"
Content-Transfer-Encoding: 7Bit
Content-Type: text/x-patch; charset="UTF-8"; name="0013-New-config-variable-CONFIG_MENU.patch"
More information about the U-Boot
mailing list