r2235 - trunk/src/target/u-boot/patches
werner at sita.openmoko.org
werner at sita.openmoko.org
Wed Jun 13 00:57:49 CEST 2007
Author: werner
Date: 2007-06-13 00:57:45 +0200 (Wed, 13 Jun 2007)
New Revision: 2235
Modified:
trunk/src/target/u-boot/patches/boot-menu.patch
Log:
Patch for common/bootmenu.c was garbled, sorry.
Modified: trunk/src/target/u-boot/patches/boot-menu.patch
===================================================================
--- trunk/src/target/u-boot/patches/boot-menu.patch 2007-06-12 18:05:49 UTC (rev 2234)
+++ trunk/src/target/u-boot/patches/boot-menu.patch 2007-06-12 22:57:45 UTC (rev 2235)
@@ -364,322 +364,258 @@
OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))
Index: u-boot/common/bootmenu.c
===================================================================
---- u-boot.orig/common/bootmenu.c
+--- /dev/null
+++ u-boot/common/bootmenu.c
-@@ -22,18 +22,13 @@
-
-
- #include <common.h>
+@@ -0,0 +1,311 @@
++/*
++ * bootmenu.c - Boot menu
++ *
++ * Copyright (C) 2006-2007 by OpenMoko, Inc.
++ * Written by Werner Almesberger <werner at openmoko.org>
++ * All Rights Reserved
++ *
++ * 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.,
++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
++ */
+
++
++#include <common.h>
++
+#ifdef CFG_BOOTMENU
+
+#include <malloc.h>
- #include <devices.h>
- #include <console.h>
--#include <environment.h>
--#include <environment.h>
--#include <asm/atomic.h>
--
--#ifdef CONFIG_USBD_DFU
--#include "usbdcore.h"
--#include "usb_dfu.h"
--#endif
--
--#include "neo1973.h"
++#include <devices.h>
++#include <console.h>
+#include <bootmenu.h>
-
-
- extern const char version_string[];
-@@ -44,8 +39,6 @@ extern const char version_string[];
- #define ANSI_NORMAL "\e[m"
- #define ANSI_GOTOYX "\e[%d;%dH"
-
--#define DEBOUNCE_LOOPS 1000 /* wild guess */
--
- /*
- * MIN_BOOT_MENU_TIMEOUT ensures that users can't by accident set the timeout
- * unusably short.
-@@ -58,29 +51,18 @@ extern const char version_string[];
- #define TOP_ROW 2
- #define MENU_0_ROW (TOP_ROW+5)
-
--#define BOOT_TXT "Boot"
--#define FACTORY_TXT "Factory reset"
-
++
++
++extern const char version_string[];
++
++
++#define ANSI_CLEAR "\e[2J"
++#define ANSI_REVERSE "\e[7m"
++#define ANSI_NORMAL "\e[m"
++#define ANSI_GOTOYX "\e[%d;%dH"
++
++/*
++ * MIN_BOOT_MENU_TIMEOUT ensures that users can't by accident set the timeout
++ * unusably short.
++ */
++#define MIN_BOOT_MENU_TIMEOUT 10 /* 10 seconds */
++#define BOOT_MENU_TIMEOUT 60 /* 60 seconds */
++#define AFTER_COMMAND_WAIT 3 /* wait (2,3] after running commands */
++#define MAX_MENU_ITEMS 10 /* cut off after that many */
++
++#define TOP_ROW 2
++#define MENU_0_ROW (TOP_ROW+5)
++
++
+struct option {
+ const char *label;
+ void (*fn)(void *user); /* run_command if NULL */
+ void *user;
+};
-
--/*
-- * The menu options are indexed as follows:
-- *
-- * 0 Hard-coded "Boot"
-- * n User-provided options
-- * options+1 Hard-coded "Factory reset"
-- *
-- * "options" is the number of user-provided options. They are stored in
-- * environment variables names "menu_N", starting with 1.
-- *
-- * Because there can be * holes in the sequence of "menu_N" variables, we use
-- * map[] to map the option number to the number in the variable name. The
-- * first variable goes into map[1], etc., so that, if we start with menu_1 and
-- * have no holes, map[i] == i for 1 <= i <= options.
-- */
-
--static int map[MAX_MENU_ITEMS];
--static int options = 0;
--static int width = sizeof(FACTORY_TXT)-1;
++
++
+static const struct bootmenu_setup *setup;
+static struct option options[MAX_MENU_ITEMS];
+static int num_options = 0;
+static int max_width = 0;
-
- static device_t *bm_con;
-
-@@ -98,80 +80,28 @@ static void bm_printf(const char *fmt, .
- }
-
-
--static int debounce(int (*fn)(void), int last)
--{
-- int on, i;
--
--again:
-- on = fn();
-- if (on != last)
-- for (i = DEBOUNCE_LOOPS; i; i--)
-- if (on != fn())
-- goto again;
-- return on;
--}
--
--
- static char *get_option(int n)
- {
- char name[] = "menu_XX";
-
-- sprintf(name+5,"%d",map[n]);
++
++static device_t *bm_con;
++
++
++static void bm_printf(const char *fmt, ...)
++{
++ va_list args;
++ char printbuffer[CFG_PBSIZE];
++
++ va_start(args, fmt);
++ vsprintf(printbuffer, fmt, args);
++ va_end(args);
++
++ bm_con->puts(printbuffer);
++}
++
++
++static char *get_option(int n)
++{
++ char name[] = "menu_XX";
++
+ sprintf(name+5, "%d", n);
- return getenv(name);
- }
-
-
--static void print_option_n(int n)
++ return getenv(name);
++}
++
++
+static void print_option(const struct option *option, int reverse)
- {
-- char *s, *colon;
-- int len;
--
-- if (!n) {
-- bm_printf(" %-*s ", width, BOOT_TXT);
-- return;
-- }
-- if (n == options+1) {
-- bm_printf(" %-*s ", width, FACTORY_TXT);
-- return;
-- }
-- s = get_option(n);
-- if (!s)
-- return;
-- colon = strchr(s, ':');
-- if (colon)
-- *colon = 0;
-- len = strlen(s);
-- if (len > width)
-- width = len;
-- bm_printf(" %-*s ", width, s);
-- if (colon)
-- *colon = ':';
--}
++{
+ int n = option-options;
-
--
--static void print_option(int n, int reverse)
--{
- bm_printf(ANSI_GOTOYX, MENU_0_ROW+n, 1);
- if (reverse)
- bm_printf(ANSI_REVERSE);
-- print_option_n(n);
++
++ bm_printf(ANSI_GOTOYX, MENU_0_ROW+n, 1);
++ if (reverse)
++ bm_printf(ANSI_REVERSE);
+ bm_printf(" %-*s ", max_width, option->label);
- if (reverse)
- bm_printf(ANSI_NORMAL);
- }
-
-
--static const char *option_command(int n)
--{
-- const char *s, *colon;
--
-- s = get_option(n);
-- if (!s)
-- return NULL;
-- colon = strchr(s, ':');
-- return colon ? colon+1 : s;
--}
--
--
- static int get_var_positive_int(char *var, int default_value)
- {
- const char *s;
-@@ -188,32 +118,16 @@ static int get_var_positive_int(char *va
- }
-
-
--static void init_bootmenu(void)
++ if (reverse)
++ bm_printf(ANSI_NORMAL);
++}
++
++
++static int get_var_positive_int(char *var, int default_value)
++{
++ const char *s;
++ char *end;
++ int n;
++
++ s = getenv(var);
++ if (!s)
++ return default_value;
++ n = simple_strtoul(s, &end, 0);
++ if (!*s || *end || n < 1)
++ return default_value;
++ return n;
++}
++
++
+static void show_bootmenu(void)
- {
-- int n;
++{
+ const struct option *option;
-
- bm_printf(ANSI_CLEAR ANSI_GOTOYX "%s", TOP_ROW, 1, version_string);
- bm_printf(ANSI_GOTOYX "*** BOOT MENU ***", TOP_ROW+3, 1);
- bm_printf(ANSI_GOTOYX, MENU_0_ROW, 1);
-
-- options = 0;
--
-- /* hard-coded first option */
-- print_option(0, 1);
-- map[0] = 0;
--
-- /* user-provided options */
-- for (n = 1; n != MAX_MENU_ITEMS+1; n++) {
-- map[options+1] = n;
-- if (option_command(options+1)) {
-- options++;
-- print_option(options, 0);
-- }
-- }
--
-- /* hard-coded last option */
-- print_option(options+1, 0);
-- map[options+1] = options+1;
++
++ bm_printf(ANSI_CLEAR ANSI_GOTOYX "%s", TOP_ROW, 1, version_string);
++ bm_printf(ANSI_GOTOYX "*** BOOT MENU ***", TOP_ROW+3, 1);
++ bm_printf(ANSI_GOTOYX, MENU_0_ROW, 1);
++
+ for (option = options; option != options+num_options; option++)
+ print_option(option, option == options);
-
- bm_printf("\n\nPress [AUX] to select, [POWER] to execute.\n");
- }
-@@ -242,42 +156,18 @@ static void redirect_console(int grab)
- }
-
-
--static int system_idle(void)
--{
--#ifdef CONFIG_USBD_DFU
-- if (system_dfu_state)
-- return *system_dfu_state == DFU_STATE_appIDLE;
--#endif
-- return 1;
--}
--
--
--static void poweroff_if_idle(void)
--{
-- unsigned long flags;
--
-- local_irq_save(flags);
-- if (system_idle())
-- neo1973_poweroff();
-- local_irq_restore(flags);
--}
--
--
--static void do_option(int option)
++
++ bm_printf("\n\nPress [AUX] to select, [POWER] to execute.\n");
++}
++
++
++static void redirect_console(int grab)
++{
++ static device_t *orig_stdout, *orig_stderr;
++
++ if (grab) {
++ orig_stdout = stdio_devices[stdout];
++ orig_stderr = stdio_devices[stderr];
++ stdio_devices[stdout] = bm_con;
++ stdio_devices[stderr] = bm_con;
++ }
++ else {
++ /*
++ * Make this conditional, because the command may also change
++ * the console.
++ */
++ if (stdio_devices[stdout] == bm_con)
++ stdio_devices[stdout] = orig_stdout;
++ if (stdio_devices[stderr] == bm_con)
++ stdio_devices[stderr] = orig_stderr;
++ }
++}
++
++
+static void do_option(const struct option *option)
- {
- int seconds, aux;
-
- bm_printf(ANSI_CLEAR ANSI_GOTOYX, 1, 1);
- redirect_console(1);
-- if (!option || option == options+1) {
-- if (option) {
-- default_env();
-- run_command("dynpart", 0);
-- }
-- run_command("bootd", 0);
-- }
++{
++ int seconds, aux;
+
++ bm_printf(ANSI_CLEAR ANSI_GOTOYX, 1, 1);
++ redirect_console(1);
++
+ if (option->fn)
+ option->fn(option->user);
- else
-- run_command(option_command(option), 0);
++ else
+ run_command(option->user, 0);
+
- redirect_console(0);
- seconds = get_var_positive_int("after_command_wait",
- AFTER_COMMAND_WAIT);
-@@ -288,46 +178,46 @@ static void do_option(int option)
- while (seconds) {
- int tmp;
-
-- tmp = debounce(neo1973_aux_key_pressed, aux);
++ redirect_console(0);
++ seconds = get_var_positive_int("after_command_wait",
++ AFTER_COMMAND_WAIT);
++ if (seconds)
++ bm_printf("\nPress [AUX] to %s.",
++ option ? "return to boot menu" : "power off");
++ aux = 1; /* require up-down transition */
++ while (seconds) {
++ int tmp;
++
+ tmp = setup->next_key(setup->user);
- if (tmp && !aux)
- break;
- aux = tmp;
-- if (neo1973_new_second())
++ if (tmp && !aux)
++ break;
++ aux = tmp;
+ if (setup->seconds(setup->user))
- seconds--;
- }
- if (!option)
-- poweroff_if_idle();
-- init_bootmenu();
++ seconds--;
++ }
++ if (!option)
+ setup->idle_action(setup->idle_action);
+ show_bootmenu();
- }
-
-
- static void bootmenu_hook(int activity)
- {
- static int aux = 1, on = 1;
-- static int option = 0;
++}
++
++
++static void bootmenu_hook(int activity)
++{
++ static int aux = 1, on = 1;
+ static const struct option *option = options;
- static int seconds = 0;
- int tmp;
-
- if (activity)
- seconds = 0;
-- tmp = debounce(neo1973_aux_key_pressed, aux);
++ static int seconds = 0;
++ int tmp;
++
++ if (activity)
++ seconds = 0;
+ tmp = setup->next_key(setup->user);
- if (tmp && !aux) {
- print_option(option, 0);
- option++;
-- if (option == options+2)
-- option = 0;
++ if (tmp && !aux) {
++ print_option(option, 0);
++ option++;
+ if (option == options+num_options)
+ option = options;
- print_option(option, 1);
- seconds = 0;
- }
- aux = tmp;
-- tmp = debounce(neo1973_on_key_pressed, on);
++ print_option(option, 1);
++ seconds = 0;
++ }
++ aux = tmp;
+ tmp = setup->enter_key(setup->user);
- if (tmp && !on) {
- do_option(option);
-- option = 0;
++ if (tmp && !on) {
++ do_option(option);
+ option = options;
- seconds = 0;
- }
- on = tmp;
-- if (neo1973_new_second()) {
++ seconds = 0;
++ }
++ on = tmp;
+ if (setup->seconds(setup->user)) {
- int timeout;
-
- timeout = get_var_positive_int("boot_menu_timeout",
-@@ -335,7 +225,7 @@ static void bootmenu_hook(int activity)
- if (timeout < MIN_BOOT_MENU_TIMEOUT)
- timeout = MIN_BOOT_MENU_TIMEOUT;
- if (++seconds > timeout) {
-- poweroff_if_idle();
++ int timeout;
++
++ timeout = get_var_positive_int("boot_menu_timeout",
++ BOOT_MENU_TIMEOUT);
++ if (timeout < MIN_BOOT_MENU_TIMEOUT)
++ timeout = MIN_BOOT_MENU_TIMEOUT;
++ if (++seconds > timeout) {
+ setup->idle_action(setup->idle_action);
- seconds = 0;
- }
- }
-@@ -357,6 +247,50 @@ static device_t *find_console(const char
- }
-
-
++ seconds = 0;
++ }
++ }
++}
++
++
++static device_t *find_console(const char *name)
++{
++ int i;
++
++ for (i = 1; i != ListNumItems(devlist); i++) {
++ device_t *dev = ListGetPtrToItem(devlist, i);
++
++ if (!strcmp(name, dev->name))
++ if (dev->flags & DEV_FLAGS_OUTPUT)
++ return dev;
++ }
++ return NULL;
++}
++
++
+void bootmenu_add(const char *label, void (*fn)(void *user), void *user)
+{
+ int len;
@@ -724,17 +660,22 @@
+}
+
+
- void bootmenu(void)
- {
- bm_con = find_console("vga");
-@@ -370,6 +304,8 @@ void bootmenu(void)
- console_assign(stdout, "vga");
- console_assign(stderr, "vga");
- #endif
-- init_bootmenu();
++void bootmenu(void)
++{
++ bm_con = find_console("vga");
++ if (bm_con && bm_con->start && bm_con->start() < 0)
++ bm_con = NULL;
++ if (!bm_con)
++ bm_con = stdio_devices[stdout];
++ if (!bm_con)
++ return;
++#if 0
++ console_assign(stdout, "vga");
++ console_assign(stderr, "vga");
++#endif
+ show_bootmenu();
- console_poll_hook = bootmenu_hook;
- }
++ console_poll_hook = bootmenu_hook;
++}
+
+#endif /* CFG_BOOTMENU */
Index: u-boot/include/bootmenu.h
More information about the commitlog
mailing list