📄 boot-menu.patch
字号:
board/neo1973/bootmenu.c: simple configurable boot menuboard/neo1973/neo1973.c (neo1973_new_second): return 1 if a new second has started since the last callboard/neo1973/neo1973.c (neo1973_on_key_pressed): return 1 if the $POWER key is pressedboard/neo1973/neo1973.c (board_late_init): make use of neo1973_new_second and neo1973_on_key_pressedboard/neo1973/neo1973.h: added function prototypesu-boot/board/neo1973/neo1973.c (board_late_init): enter the boot menu when "AUX" was pressed at least half the timeu-boot/board/neo1973/neo1973.c (board_late_init): minor code cleanupu-boot/common/console.c, include/console.h: added "console_poll_hook" to be called when waiting for console in put in "getc" and "tstc"board/neo1973/neo1973.c (board_late_init): poll for the boot menu also on RAM boot, reset, or unknown causeboard/neo1973/neo1973.c (board_late_init): don't look for the power key if woken up by the chargerboard/neo1973/neo1973.h, board/neo1973/neo1973.c, board/neo1973/bootmenu.c: renamed neo1973_911_key_pressed to neo1973_aux_key_pressed- Werner Almesberger <werner@openmoko.org>Index: u-boot/board/neo1973/common/bootmenu.c===================================================================--- /dev/null+++ u-boot/board/neo1973/common/bootmenu.c@@ -0,0 +1,113 @@+/*+ * bootmenu.c - Boot menu+ *+ * Copyright (C) 2006-2007 by OpenMoko, Inc.+ * Written by Werner Almesberger <werner@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 <bootmenu.h>+#include <asm/atomic.h>++#ifdef CONFIG_USBD_DFU+#include "usbdcore.h"+#include "usb_dfu.h"+#endif++#include "neo1973.h"+++#define DEBOUNCE_LOOPS 1000 /* wild guess */+++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;+ *last = on;+ return on;+}+++static int aux_key(void *user)+{+ static int last_aux = -1;++ return debounce(neo1973_aux_key_pressed, &last_aux);+}+++static int on_key(void *user)+{+ static int last_on = -1;++ return debounce(neo1973_on_key_pressed, &last_on);+}+++static int seconds(void *user)+{+ return neo1973_new_second();+}+++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 *user)+{+ unsigned long flags;++ local_irq_save(flags);+ if (system_idle())+ neo1973_poweroff();+ local_irq_restore(flags);+}+++static struct bootmenu_setup bootmenu_setup = {+ .next_key = aux_key,+ .enter_key = on_key,+ .seconds = seconds,+ .idle_action = poweroff_if_idle,+ .next_key_action = "Press [AUX]",+ .enter_key_name = "[POWER]",+};+++void neo1973_bootmenu(void)+{+ bootmenu_add("Boot", NULL, "bootd");+ bootmenu_init(&bootmenu_setup);+ bootmenu();+}Index: u-boot/board/neo1973/gta01/gta01.c===================================================================--- u-boot.orig/board/neo1973/gta01/gta01.c+++ u-boot/board/neo1973/gta01/gta01.c@@ -230,10 +230,15 @@ int board_late_init(void) extern unsigned char booted_from_nand; unsigned char tmp; char buf[32];+ int menu_vote = 0; /* <= 0: no, > 0: yes */+ int seconds = 0; /* Initialize the Power Management Unit with a safe register set */ pcf50606_init(); + /* if there's no other reason, must be regular reset */+ neo1973_wakeup_cause = NEO1973_WAKEUP_RESET;+ if (!booted_from_nand) goto woken_by_reset; @@ -243,45 +248,41 @@ int board_late_init(void) setenv("pcf50606_int1", buf); if (tmp & PCF50606_INT1_ALARM) {- /* we've been woken up by RTC alarm or charger insert, boot */+ /* we've been woken up by RTC alarm, boot */ neo1973_wakeup_cause = NEO1973_WAKEUP_ALARM; goto continue_boot; } if (tmp & PCF50606_INT1_EXTONR) {+ /* we've been woken up by charger insert */ neo1973_wakeup_cause = NEO1973_WAKEUP_CHARGER; } if (tmp & PCF50606_INT1_ONKEYF) {- int seconds = 0;- neo1973_wakeup_cause = NEO1973_WAKEUP_POWER_KEY; /* we've been woken up by a falling edge of the onkey */+ neo1973_wakeup_cause = NEO1973_WAKEUP_POWER_KEY;+ } - /* we can't just setenv(bootdelay,-1) because that would- * accidentially become permanent if the user does saveenv */- if (neo1973_911_key_pressed())- nobootdelay = 1;-- while (1) {- u_int8_t int1, oocs;-- oocs = pcf50606_reg_read(PCF50606_REG_OOCS);- if (oocs & PFC50606_OOCS_ONKEY)- break;-- int1 = pcf50606_reg_read(PCF50606_REG_INT1);- if (int1 & PCF50606_INT1_SECOND)- seconds++;-- if (seconds >= POWER_KEY_SECONDS)- goto continue_boot;- }- /* Power off if minimum number of seconds not reached */- neo1973_poweroff();+ if (neo1973_wakeup_cause == NEO1973_WAKEUP_CHARGER) {+ /* if we still think it was only a charger insert, boot */+ goto continue_boot; } woken_by_reset:- /* if there's no other reason, must be regular reset */- neo1973_wakeup_cause = NEO1973_WAKEUP_RESET;++ while (neo1973_wakeup_cause == NEO1973_WAKEUP_RESET ||+ neo1973_on_key_pressed()) {+ if (neo1973_aux_key_pressed())+ menu_vote++;+ else+ menu_vote--;++ if (neo1973_new_second())+ seconds++;+ if (seconds >= POWER_KEY_SECONDS)+ goto continue_boot;+ }+ /* Power off if minimum number of seconds not reached */+ neo1973_poweroff(); continue_boot: jbt6k74_init();@@ -305,6 +306,11 @@ continue_boot: } #endif + if (menu_vote > 0) {+ neo1973_bootmenu();+ nobootdelay = 1;+ }+ return 0; } @@ -433,7 +439,17 @@ void neo1973_gps(int on) printf("not implemented yet!\n"); } -int neo1973_911_key_pressed(void)+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_aux_key_pressed(void) { S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); if (gpio->GPFDAT & (1 << 6))Index: u-boot/board/neo1973/gta01/Makefile===================================================================--- u-boot.orig/board/neo1973/gta01/Makefile+++ u-boot/board/neo1973/gta01/Makefile@@ -26,7 +26,7 @@ include $(TOPDIR)/config.mk LIB = lib$(BOARD).a OBJS := gta01.o pcf50606.o ../common/cmd_neo1973.o ../common/jbt6k74.o \- ../common/gsmver.o ../common/udc.o+ ../common/gsmver.o ../common/udc.o ../common/bootmenu.o SOBJS := ../common/lowlevel_init.o .PHONY: allIndex: u-boot/board/neo1973/common/neo1973.h===================================================================--- u-boot.orig/board/neo1973/common/neo1973.h+++ u-boot/board/neo1973/common/neo1973.h@@ -32,4 +32,10 @@ int neo1973_911_key_pressed(void); const char *neo1973_get_charge_status(void); int neo1973_set_charge_mode(enum neo1973_charger_cmd cmd); +int neo1973_new_second(void);+int neo1973_on_key_pressed(void);+int neo1973_aux_key_pressed(void);++void neo1973_bootmenu(void);+ #endifIndex: u-boot/common/console.c===================================================================--- u-boot.orig/common/console.c+++ u-boot/common/console.c@@ -160,8 +160,12 @@ void fprintf (int file, const char *fmt, /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/ +void (*console_poll_hook)(int activity);+ int getc (void) {+ while (console_poll_hook && !tstc());+ if (gd->flags & GD_FLG_DEVINIT) { /* Get from the standard input */ return fgetc (stdin);@@ -171,7 +175,7 @@ int getc (void) return serial_getc (); } -int tstc (void)+static int do_tstc (void) { if (gd->flags & GD_FLG_DEVINIT) { /* Test the standard input */@@ -182,6 +186,16 @@ int tstc (void) return serial_tstc (); } +int tstc (void)+{+ int ret;++ ret = do_tstc();+ if (console_poll_hook)+ console_poll_hook(ret);+ return ret;+}+ void putc (const char c) { #ifdef CONFIG_SILENT_CONSOLEIndex: u-boot/include/console.h===================================================================--- u-boot.orig/include/console.h+++ u-boot/include/console.h@@ -33,6 +33,8 @@ extern device_t *stdio_devices[] ; extern char *stdio_names[MAX_FILES] ; +extern void (*console_poll_hook)(int activity);+ int console_realloc(int top); #endifIndex: u-boot/common/Makefile===================================================================--- u-boot.orig/common/Makefile+++ u-boot/common/Makefile@@ -31,6 +31,7 @@ COBJS-y += main.o COBJS-y += ACEX1K.o COBJS-y += altera.o COBJS-y += bedbug.o+COBJS-y += bootmenu.o COBJS-y += circbuf.o COBJS-y += cmd_autoscript.o COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.oIndex: u-boot/common/bootmenu.c===================================================================--- /dev/null+++ u-boot/common/bootmenu.c@@ -0,0 +1,316 @@+/*+ * bootmenu.c - Boot menu+ *+ * Copyright (C) 2006-2007 by OpenMoko, Inc.+ * Written by Werner Almesberger <werner@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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -