r1093 - trunk/src/target/u-boot/patches
werner at sita.openmoko.org
werner at sita.openmoko.org
Sat Feb 24 06:42:51 CET 2007
Author: werner
Date: 2007-02-24 06:42:28 +0100 (Sat, 24 Feb 2007)
New Revision: 1093
Added:
trunk/src/target/u-boot/patches/boot-menu.patch
trunk/src/target/u-boot/patches/console-ansi.patch
trunk/src/target/u-boot/patches/default-env.patch
Modified:
trunk/src/target/u-boot/patches/series
Log:
default-env.patch: provide a central "reset to default environment" function
console-ansi.patch: add basic ANSI escape sequence processing to cfb-console
boot-menu.patch: add a boot menu
Added: trunk/src/target/u-boot/patches/boot-menu.patch
===================================================================
--- trunk/src/target/u-boot/patches/boot-menu.patch 2007-02-24 02:27:50 UTC (rev 1092)
+++ trunk/src/target/u-boot/patches/boot-menu.patch 2007-02-24 05:42:28 UTC (rev 1093)
@@ -0,0 +1,276 @@
+board/neo1973/bootmenu.c: simple configurable boot menu
+board/neo1973/neo1973.c (neo1973_new_second): return 1 if a new second has
+ started since the last call
+board/neo1973/neo1973.c (neo1973_on_key_pressed): return 1 if the $POWER key is
+ pressed
+board/neo1973/neo1973.c (board_late_init): make use of neo1973_new_second and
+ neo1973_on_key_pressed, call "bootmenu" if AUX is pressed with POWER
+board/neo1973/Makefile: added bootmenu.c
+board/neo1973/neo1973.h: added function prototypes
+
+- Werner Almesberger <werner at openmoko.org>
+
+Index: u-boot/board/neo1973/bootmenu.c
+===================================================================
+--- /dev/null
++++ u-boot/board/neo1973/bootmenu.c
+@@ -0,0 +1,181 @@
++/*
++ * bootmenu.c - Convert a 480x640 PNG to a splash screen raw dump
++ *
++ * 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>
++#include <environment.h>
++
++#include "neo1973.h"
++
++
++#define ANSI_CLEAR "\e[2J"
++#define ANSI_REVERSE "\e[7m"
++#define ANSI_NORMAL "\e[m"
++#define ANSI_GOTOYX "\e[%d;%dH"
++
++#define DEBOUNCE_LOOPS 1000 /* wild guess */
++#define BOOT_MENU_TIMEOUT 60 /* 60 second */
++#define AFTER_COMMAND_WAIT 3 /* wait (2,3] after running commands */
++#define MAX_MENU_ITEMS 10 /* cut off after that many */
++
++#define BOOT_TXT "Boot"
++#define FACTORY_TXT "Factory reset"
++
++
++static int options = 0;
++static int width = sizeof(FACTORY_TXT)-1;
++
++
++static int debounce(int (*fn)(void))
++{
++ int on, i;
++
++again:
++ on = fn();
++ 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",n);
++ return getenv(name);
++}
++
++
++static void print_option_n(int n)
++{
++ char *s, *colon;
++ int len;
++
++ if (!n) {
++ printf(" %-*s ", width, BOOT_TXT);
++ return;
++ }
++ if (n == options+1) {
++ 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;
++ printf(" %-*s ", width, s);
++ if (colon)
++ *colon = ':';
++}
++
++
++static void print_option(int n, int reverse)
++{
++ printf(ANSI_GOTOYX, n+4, 1);
++ if (reverse)
++ printf(ANSI_REVERSE);
++ print_option_n(n);
++ if (reverse)
++ 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 do_bootmenu(void)
++{
++ int aux = 1, on = 1;
++ int n, seconds = 0;
++
++ printf(ANSI_CLEAR ANSI_GOTOYX "*** BOOT MENU ***\n\n", 2, 1);
++ print_option(0, 1);
++ while (options < MAX_MENU_ITEMS && option_command(options+1))
++ print_option(++options, 0);
++ print_option(options+1, 0);
++ printf("\n\nPress [AUX] to select, [POWER] to execute.\n");
++
++ n = 0;
++ while (1) {
++ int tmp;
++
++ tmp = debounce(neo1973_911_key_pressed);
++ if (tmp && !aux) {
++ print_option(n, 0);
++ n++;
++ if (n == options+2)
++ n = 0;
++ print_option(n, 1);
++ seconds = 0;
++ }
++ aux = tmp;
++ tmp = debounce(neo1973_on_key_pressed);
++ if (tmp && !on)
++ return n;
++ on = tmp;
++ if (neo1973_new_second())
++ if (++seconds > BOOT_MENU_TIMEOUT)
++ return -1;
++ }
++}
++
++
++void bootmenu(void)
++{
++ while (1) {
++ int n, seconds;
++
++ options = 0;
++ n = do_bootmenu();
++ if (n < 0)
++ return;
++
++ printf(ANSI_CLEAR ANSI_GOTOYX, 1, 1);
++ if (!n || n == options+1) {
++ if (n)
++ default_env();
++ run_command("bootd", 0);
++ }
++ else
++ run_command(option_command(n), 0);
++ seconds = AFTER_COMMAND_WAIT;
++ while (seconds)
++ if (neo1973_new_second())
++ seconds--;
++ }
++}
+Index: u-boot/board/neo1973/neo1973.c
+===================================================================
+--- u-boot.orig/board/neo1973/neo1973.c
++++ u-boot/board/neo1973/neo1973.c
+@@ -228,14 +228,10 @@ int board_late_init(void)
+ nobootdelay = 1;
+
+ while (1) {
+- u_int8_t int1, oocs;
+-
+- oocs = pcf50606_reg_read(PCF50606_REG_OOCS);
+- if (oocs & PFC50606_OOCS_ONKEY)
++ if (!neo1973_on_key_pressed())
+ break;
+
+- int1 = pcf50606_reg_read(PCF50606_REG_INT1);
+- if (int1 & PCF50606_INT1_SECOND)
++ if (neo1973_new_second())
+ seconds++;
+
+ if (seconds >= POWER_KEY_SECONDS)
+@@ -262,6 +258,11 @@ continue_boot:
+ /* switch on the backlight */
+ neo1973_backlight(1);
+
++ if (nobootdelay) {
++ bootmenu();
++ neo1973_poweroff();
++ }
++
+ return 0;
+ }
+
+@@ -313,6 +314,16 @@ void neo1973_vibrator(int on)
+ gpio->GPBDAT &= ~(1 << 10);
+ }
+
++int neo1973_new_second(void)
++{
++ return pcf50606_reg_read(PCF50606_REG_INT1) & PCF50606_INT1_SECOND;
++}
++
++int neo1973_on_key_pressed(void)
++{
++ return !(pcf50606_reg_read(PCF50606_REG_OOCS) & PFC50606_OOCS_ONKEY);
++}
++
+ int neo1973_911_key_pressed(void)
+ {
+ S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
+Index: u-boot/board/neo1973/Makefile
+===================================================================
+--- u-boot.orig/board/neo1973/Makefile
++++ u-boot/board/neo1973/Makefile
+@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
+
+ LIB = lib$(BOARD).a
+
+-OBJS := neo1973.o pcf50606.o cmd_neo1973.o jbt6k74.o
++OBJS := neo1973.o pcf50606.o cmd_neo1973.o jbt6k74.o bootmenu.o
+ SOBJS := lowlevel_init.o
+
+ .PHONY: all
+Index: u-boot/board/neo1973/neo1973.h
+===================================================================
+--- u-boot.orig/board/neo1973/neo1973.h
++++ u-boot/board/neo1973/neo1973.h
+@@ -15,4 +15,10 @@ void neo1973_poweroff(void);
+ void neo1973_backlight(int on);
+ void neo1973_vibrator(int on);
+
++int neo1973_new_second(void);
++int neo1973_on_key_pressed(void);
++int neo1973_911_key_pressed(void);
++
++void bootmenu(void);
++
+ #endif
Added: trunk/src/target/u-boot/patches/console-ansi.patch
===================================================================
--- trunk/src/target/u-boot/patches/console-ansi.patch 2007-02-24 02:27:50 UTC (rev 1092)
+++ trunk/src/target/u-boot/patches/console-ansi.patch 2007-02-24 05:42:28 UTC (rev 1093)
@@ -0,0 +1,127 @@
+drivers/cfb_console.c: added processing of ANSI escape sequences \e[2J, \e[m,
+ \e[7m, and \e[row;colH
+drivers/cfb_console.c (video_putc): make \r return to the beginning of the line
+
+- Werner Almesberger <werner at openmoko.org>
+
+Index: u-boot/drivers/cfb_console.c
+===================================================================
+--- u-boot.orig/drivers/cfb_console.c
++++ u-boot/drivers/cfb_console.c
+@@ -181,6 +181,7 @@ CONFIG_VIDEO_HW_CURSOR: - Uses the
+
+ #include <version.h>
+ #include <linux/types.h>
++#include <linux/ctype.h>
+ #include <devices.h>
+ #include <video_font.h>
+ #ifdef CFG_CMD_DATE
+@@ -676,10 +677,96 @@ static void console_newline (void)
+
+ /*****************************************************************************/
+
++static enum {
++ CS_NORMAL = 0,
++ CS_ESC,
++ CS_NUM1,
++ CS_NUM2,
++} state = 0;
++
++static int num1, num2;
++
++
++static void swap_drawing_colors(void)
++{
++ eorx = fgx;
++ fgx = bgx;
++ bgx = eorx;
++ eorx = fgx ^ bgx;
++}
++
++
++static void process_sequence(char c)
++{
++ static int inverted = 0;
++ int i, inv;
++
++ switch (c) {
++ case 'J':
++ /* assume num1 == 2 */
++ for (i = 0; i != CONSOLE_ROWS; i++)
++ console_scrollup();
++ break;
++ case 'H':
++ if (num1 > CONSOLE_ROWS || num2 > CONSOLE_COLS)
++ break;
++ console_col = num2 ? num2-1 : 0;
++ console_row = num1 ? num1-1 : 0;
++ break;
++ case 'm':
++ inv = num1 == 7;
++ if (num1 && !inv)
++ break;
++ if (inverted != inv)
++ swap_drawing_colors();
++ inverted = inv;
++ break;
++ }
++}
++
++
++static void escape_sequence(char c)
++{
++ switch (state) {
++ case CS_ESC:
++ state = c == '[' ? CS_NUM1 : CS_NORMAL;
++ num1 = num2 = 0;
++ break;
++ case CS_NUM1:
++ if (isdigit(c))
++ num1 = num1*10+c-'0';
++ else if (c == ';')
++ state = CS_NUM2;
++ else {
++ process_sequence(c);
++ state = CS_NORMAL;
++ }
++ break;
++ case CS_NUM2:
++ if (isdigit(c))
++ num2 = num2*10+c-'0';
++ else {
++ process_sequence(c);
++ state = CS_NORMAL;
++ }
++ default:
++ /* can't happen */;
++ }
++}
++
++
+ void video_putc (const char c)
+ {
++ if (state) {
++ escape_sequence(c);
++ CURSOR_SET;
++ return;
++ }
++
+ switch (c) {
+- case 13: /* ignore */
++ case 13: /* return to beginning of line */
++ CURSOR_OFF;
++ console_col = 0;
+ break;
+
+ case '\n': /* next line */
+@@ -698,6 +785,10 @@ void video_putc (const char c)
+ console_back ();
+ break;
+
++ case '\e':
++ state = CS_ESC;
++ break;
++
+ default: /* draw the char */
+ video_putchar (console_col * VIDEO_FONT_WIDTH,
+ console_row * VIDEO_FONT_HEIGHT,
Added: trunk/src/target/u-boot/patches/default-env.patch
===================================================================
--- trunk/src/target/u-boot/patches/default-env.patch 2007-02-24 02:27:50 UTC (rev 1092)
+++ trunk/src/target/u-boot/patches/default-env.patch 2007-02-24 05:42:28 UTC (rev 1093)
@@ -0,0 +1,101 @@
+common/env_common.c (default_env): new function that resets the environment to
+ the default value
+common/env_common.c (env_relocate): use default_env instead of own copy
+common/env_nand.c (env_relocate_spec): use default_env instead of own copy
+include/environment.h: added default_env prototype
+
+- Werner Almesberger <werner at openmoko.org>
+
+Index: u-boot/common/env_common.c
+===================================================================
+--- u-boot.orig/common/env_common.c
++++ u-boot/common/env_common.c
+@@ -202,6 +202,25 @@ uchar *env_get_addr (int index)
+ }
+ }
+
++void default_env(void)
++{
++ if (sizeof(default_environment) > ENV_SIZE)
++ {
++ puts ("*** Error - default environment is too large\n\n");
++ return;
++ }
++
++ memset (env_ptr, 0, sizeof(env_t));
++ memcpy (env_ptr->data,
++ default_environment,
++ sizeof(default_environment));
++#ifdef CFG_REDUNDAND_ENVIRONMENT
++ env_ptr->flags = 0xFF;
++#endif
++ env_crc_update ();
++ gd->env_valid = 1;
++}
++
+ void env_relocate (void)
+ {
+ DEBUGF ("%s[%d] offset = 0x%lx\n", __FUNCTION__,__LINE__,
+@@ -245,23 +264,8 @@ void env_relocate (void)
+ gd->env_valid = 0;
+ #endif
+
+- if (gd->env_valid == 0) {
+- if (sizeof(default_environment) > ENV_SIZE)
+- {
+- puts ("*** Error - default environment is too large\n\n");
+- return;
+- }
+-
+- memset (env_ptr, 0, sizeof(env_t));
+- memcpy (env_ptr->data,
+- default_environment,
+- sizeof(default_environment));
+-#ifdef CFG_REDUNDAND_ENVIRONMENT
+- env_ptr->flags = 0xFF;
+-#endif
+- env_crc_update ();
+- gd->env_valid = 1;
+- }
++ if (gd->env_valid == 0)
++ default_env();
+ else {
+ env_relocate_spec ();
+ }
+Index: u-boot/common/env_nand.c
+===================================================================
+--- u-boot.orig/common/env_nand.c
++++ u-boot/common/env_nand.c
+@@ -313,19 +313,7 @@ void env_relocate_spec (void)
+ static void use_default()
+ {
+ puts ("*** Warning - bad CRC or NAND, using default environment\n\n");
+-
+- if (default_environment_size > CFG_ENV_SIZE){
+- puts ("*** Error - default environment is too large\n\n");
+- return;
+- }
+-
+- memset (env_ptr, 0, sizeof(env_t));
+- memcpy (env_ptr->data,
+- default_environment,
+- default_environment_size);
+- env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
+- gd->env_valid = 1;
+-
++ default_env();
+ }
+ #endif
+
+Index: u-boot/include/environment.h
+===================================================================
+--- u-boot.orig/include/environment.h
++++ u-boot/include/environment.h
+@@ -107,4 +107,7 @@ typedef struct environment_s {
+ unsigned char data[ENV_SIZE]; /* Environment data */
+ } env_t;
+
++
++void default_env(void);
++
+ #endif /* _ENVIRONMENT_H_ */
Modified: trunk/src/target/u-boot/patches/series
===================================================================
--- trunk/src/target/u-boot/patches/series 2007-02-24 02:27:50 UTC (rev 1092)
+++ trunk/src/target/u-boot/patches/series 2007-02-24 05:42:28 UTC (rev 1093)
@@ -54,3 +54,8 @@
# for automated installation
preboot-override.patch
lowlevel_foo.patch
+
+# move these later, once the dust has settled
+default-env.patch
+console-ansi.patch
+boot-menu.patch
More information about the commitlog
mailing list