Created
May 20, 2011 01:27
-
-
Save nemith/982171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/common/lcd.c b/common/lcd.c | |
index 1787e37..41bdde1 100644 | |
--- a/common/lcd.c | |
+++ b/common/lcd.c | |
@@ -102,6 +102,11 @@ extern void lcd_setcolreg (ushort regno, | |
extern void lcd_initcolregs (void); | |
#endif | |
+#if LCD_BPP == LCD_COLOR16 | |
+static uchar pixel_size = 0; | |
+static uint pixel_line_length = 0; | |
+#endif | |
+ | |
static int lcd_getbgcolor (void); | |
static void lcd_setfgcolor (int color); | |
static void lcd_setbgcolor (int color); | |
diff --git a/common/main.c b/common/main.c | |
index 9b6685d..6689c51 100644 | |
--- a/common/main.c | |
+++ b/common/main.c | |
@@ -334,6 +334,7 @@ static __inline__ int abortboot(int bootdelay) | |
#endif /* CONFIG_BOOTDELAY >= 0 */ | |
#ifdef CONFIG_3621EVT1A | |
+#include <lcd.h> | |
#define CONVERT_X(v) #v | |
#define CONVERT(v) CONVERT_X(v) | |
@@ -435,9 +436,15 @@ extern int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]); | |
extern void lcd_enable(void); | |
extern void lcd_disable(void); | |
extern void bitmap_plot (int x, int y,uchar which); | |
+extern void lcd_puts(const char* s); | |
extern void lcd_adjust_brightness(int level); | |
extern void encore_button_rtc_ack(void); | |
+#define USER_REQ_NONE 0 | |
+#define USER_REQ_RECOVERY 1 | |
+#define USER_REQ_MENU 2 | |
+#define USER_REQ_ALT 3 | |
+ | |
/*this is where we handle dead battery scenario. We spin idle and wait for battery to be charged over | |
threshold to continue to boot to kernel*/ | |
static void Encore_boot(void) | |
@@ -446,7 +453,7 @@ static void Encore_boot(void) | |
uint16_t buf_soc=0; | |
int i ; | |
unsigned char key_pad = 0; | |
- int user_req = 0; | |
+ int user_req = USER_REQ_NONE; | |
int microvolts=0; | |
/*bit0 of charger_type represents WALL CHARGER*/ | |
@@ -512,7 +519,7 @@ static void Encore_boot(void) | |
i2c_write(0x4a,0x76,1,®,1); | |
- //These have to be done before bootcmd | |
+ //These have to be done before bootcmd | |
max17042_preinit(); | |
// Read the keypad and store any keys pressed during start | |
@@ -520,9 +527,17 @@ static void Encore_boot(void) | |
// Check if the user request recovery by holding PWR & HOME keys | |
if (gpio_pin_read(14) && (key_pad & HOME_KEY)) | |
- user_req = 1; | |
+ user_req = USER_REQ_RECOVERY; | |
+ | |
+ // Check if the user request alternate boot by holding HOME | |
+ if (key_pad & HOME_KEY) | |
+ user_req = USER_REQ_MENU; | |
+ | |
+ // Check if the user is requesting alt boot by holding VOLUP & VOLDN | |
+ if ((key_pad & VOLUP_KEY) && (key_pad & VOLDN_KEY)) | |
+ user_req = USER_REQ_ALT | |
+ | |
- | |
i=0; | |
while ( max17042_init() != 0 ) { | |
if ( i++ > 30 ) { | |
@@ -690,21 +705,45 @@ static void Encore_boot(void) | |
/*battery ok to boot*/ | |
if(cap_ok){ | |
if (user_req) { | |
+ i = 0; | |
+ int break_out = 0; | |
+ while ((i++ < FACTORY_RESET_LOOP) || break_out) | |
for (i = 0; i < FACTORY_RESET_LOOP; i++) | |
{ | |
tps65921_keypad_keys_pressed(&key_pad); | |
- if (!(key_pad & HOME_KEY)) { | |
- user_req = 0; | |
- printf("HOME_KEY held for less than %d Sec\n", FACTORY_RESET_DELAY); | |
- break; | |
- } | |
+ | |
+ switch(user_req) { | |
+ case USER_REQ_RECOVERY: | |
+ if (!(key_pad & HOME_KEY)) { | |
+ user_req = 0; | |
+ printf("HOME_KEY held for less than %d Sec\n", FACTORY_RESET_DELAY); | |
+ break_out = 1; | |
+ } | |
- /* Only require power to be held for half of the time */ | |
- if ((i < FACTORY_RESET_LOOP/2) && !gpio_pin_read(14)) { | |
- user_req = 0; | |
- printf("POWER_KEY held for less than %d/2 Sec\n", FACTORY_RESET_DELAY); | |
- break; | |
- } | |
+ /* Only require power to be held for half of the time */ | |
+ if ((i < FACTORY_RESET_LOOP/2) && !gpio_pin_read(14)) { | |
+ user_req = 0; | |
+ printf("POWER_KEY held for less than %d/2 Sec\n", FACTORY_RESET_DELAY); | |
+ break_out = 1; | |
+ } | |
+ break; | |
+ | |
+ case USER_REQ_MENU: | |
+ if (!(key_pad & HOME_KEY)) { | |
+ user_req = 0; | |
+ printf("HOME_KEY held for less than %d Sec\n", FACTORY_RESET_DELAY); | |
+ break_out = 1; | |
+ } | |
+ break; | |
+ | |
+ case USER_REQ_ALT: | |
+ if (!((key_pad & VOLUP_KEY) && (key_pad & VOLDN_KEY))) { | |
+ user_req = 0; | |
+ printf("VOLUP_KEY or VOLDN_KEY held for less than %d Sec\n", FACTORY_RESET_DELAY); | |
+ break_out = 1; | |
+ } | |
+ break; | |
+ } | |
if (((i+RESET_SECOND) % RESET_SECOND) == 0) | |
{ | |
@@ -713,13 +752,143 @@ static void Encore_boot(void) | |
udelay(RESET_TICK); | |
} | |
} | |
- if (user_req) { | |
- setenv("forcerecovery", "2"); | |
- printf("Booting into Factory Reset Kernel\n"); | |
- } | |
- else { | |
- setenv("forcerecovery", "0"); | |
- printf("Booting into Normal Kernel\n"); | |
+ | |
+ switch (user_req) { | |
+ | |
+ case USER_REQ_RECOVERY: | |
+ setenv("forcerecovery", "2"); | |
+ printf("Booting into Factory Reset Kernel\n"); | |
+ break; | |
+ | |
+ case USER_REQ_MENU: | |
+ int opt, ret; | |
+ unsigned char key; | |
+ char *dev_list[2] = {" eMMC ", " SD "}; | |
+ char *mode_list[3] = {" normal ", " recovery ", " alternate "}; | |
+ int dev_idx = 0; int mode_idx = 0; int *idx; | |
+ | |
+ lcd_puts("Entering boot menu...\n"); | |
+ udelay(2000*1000); | |
+ lcd_clear(0,0,0,0); | |
+ lcd_puts("Boot options\n"); | |
+ lcd_puts("------------\n\n"); | |
+ lcd_puts("Boot Device:\n"); // row 3 | |
+ lcd_puts("Boot Mode :\n"); // row 4 | |
+ lcd_console_setpos(10, 0); | |
+ lcd_puts("Keys\n"); | |
+ lcd_puts("-----\n\n"); | |
+ lcd_puts("Press Vol- to change alternatives for highlighted option.\n"); | |
+ lcd_puts("Press Home to move highlight to next option and continue.\n"); | |
+ lcd_puts("Press Vol+ to move highlight to previous option.\n"); | |
+ lcd_console_setpos(36, 0); | |
+ //lcd_puts(BOOT_MENU_VERSION_STRING); | |
+ opt = 0; | |
+ idx = &dev_idx; | |
+ | |
+ while(opt != 2) | |
+ { | |
+ if(idx == &dev_idx && opt == 0) | |
+ lcd_console_setcolor(CONSOLE_COLOR_BLACK, CONSOLE_COLOR_WHITE); | |
+ else | |
+ lcd_console_setcolor(CONSOLE_COLOR_WHITE, CONSOLE_COLOR_BLACK); | |
+ lcd_console_setpos(3, 12); | |
+ lcd_puts(dev_list[dev_idx]); | |
+ | |
+ if(idx == &mode_idx && opt == 0) | |
+ lcd_console_setcolor(CONSOLE_COLOR_BLACK, CONSOLE_COLOR_WHITE); | |
+ else | |
+ lcd_console_setcolor(CONSOLE_COLOR_WHITE, CONSOLE_COLOR_BLACK); | |
+ lcd_console_setpos(4, 12); | |
+ lcd_puts(mode_list[mode_idx]); | |
+ | |
+ lcd_console_setcolor(CONSOLE_COLOR_WHITE, CONSOLE_COLOR_BLACK); | |
+ lcd_console_setpos(6, 0); | |
+ if(opt == 1) | |
+ lcd_puts("Press Home to boot now, Vol+ to go back to selection"); | |
+ else | |
+ lcd_puts(" "); | |
+ | |
+ do | |
+ { | |
+ key = 0; | |
+ ret = tps65921_keypad_keys_pressed(&key); | |
+ | |
+ if(ret) | |
+ { | |
+ udelay(RESET_TICK*5); | |
+ // When home is pressed then switch selection from device to mode | |
+ // if already at mode, then continue booting | |
+ if(key & HOME_KEY) | |
+ { | |
+ // opt == 1 means, its almost ready to boot. | |
+ if(opt == 1) opt = 2; | |
+ | |
+ // since selection is already at mode, we need one more | |
+ // press to boot, opt == 1 displays the confirmation. | |
+ if(idx == &mode_idx && opt == 0) | |
+ opt = 1; | |
+ | |
+ // Advance to mode selection | |
+ idx = &mode_idx; | |
+ } | |
+ | |
+ // Vol- iterates thru alternatives | |
+ if(key & VOLDN_KEY && opt == 0) | |
+ { | |
+ if(idx == &dev_idx) | |
+ *idx = (*idx+1)%2; | |
+ else | |
+ *idx = (*idx+1)%3; | |
+ } | |
+ | |
+ // Vol+ switches selection from mode to device | |
+ if(key & VOLUP_KEY) | |
+ { | |
+ if(idx == &mode_idx) | |
+ idx = &dev_idx; | |
+ | |
+ // Bail before boot? | |
+ if(opt==1) opt = 0; | |
+ } | |
+ } | |
+ udelay(RESET_TICK); | |
+ } while(!ret); | |
+ } | |
+ | |
+ lcd_console_setcolor(CONSOLE_COLOR_WHITE, CONSOLE_COLOR_BLACK); | |
+ lcd_console_setpos(6, 0); | |
+ lcd_puts("Booting selected option, please wait... "); | |
+ | |
+ // override u-boot.order if present | |
+ setenv("customboot", "1"); | |
+ | |
+ // Set the boot device | |
+ if(dev_idx == 0) | |
+ setenv("bootdevice", "eMMC"); | |
+ else | |
+ setenv("bootdevice", "SD"); | |
+ | |
+ // If recovery is selected | |
+ if(mode_idx == 1) | |
+ setenv("forcerecovery", "2"); | |
+ else | |
+ setenv("forcerecovery", "0"); | |
+ | |
+ // If alternate booting is required | |
+ if(mode_idx == 2) | |
+ setenv("bootvar", "altboot"); | |
+ | |
+ | |
+ case USER_REQ_ALT: | |
+ setenv("bootvar", "altboot"); | |
+ printf("Booting into alternate kernel/ramdisk\n"); | |
+ break; | |
+ | |
+ default: | |
+ setenv("forcerecovery", "0"); | |
+ setenv("customboot", "0"); | |
+ printf("Booting into Normal Kernel\n"); | |
+ break; | |
/* note: this does not currently over-write what is in the bcb. | |
* Action on forcerecovery == 0 could read back the bcb and |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment