static void blink_sys_led(int stage) { all_led_off(); if(stage) { int d=100; int count=stage; int rest=1000-(stage*2*d); int i=0; for(; i < count; ++i) { all_led_on(); milisecdelay(d); all_led_off(); milisecdelay(d); } milisecdelay(rest); } else { milisecdelay(1000); } }
// info about current progress of failsafe mode int do_http_progress(const int state){ unsigned char i = 0; /* toggle LED's here */ switch(state){ case WEBFAILSAFE_PROGRESS_START: // blink LED fast 10 times for(i = 0; i < 10; ++i){ all_led_on(); milisecdelay(25); all_led_off(); milisecdelay(25); } printf("HTTP server is ready!\n\n"); break; case WEBFAILSAFE_PROGRESS_TIMEOUT: //printf("Waiting for request...\n"); break; case WEBFAILSAFE_PROGRESS_UPLOAD_READY: printf("HTTP upload is done! Upgrading...\n"); break; case WEBFAILSAFE_PROGRESS_UPGRADE_READY: printf("HTTP ugrade is done! Rebooting...\n\n"); break; case WEBFAILSAFE_PROGRESS_UPGRADE_FAILED: printf("## Error: HTTP ugrade failed!\n\n"); // blink LED fast for 4 sec for(i = 0; i < 80; ++i){ all_led_on(); milisecdelay(25); all_led_off(); milisecdelay(25); } // wait 1 sec milisecdelay(1000); break; } return(0); }
static void blink_led(int count,int delay) { int i=0; all_led_off(); for(; i < count; ++i) { all_led_on(); milisecdelay(delay); all_led_off(); milisecdelay(delay); } }
static void blink_sys_led(int counter) { all_led_off(); if((counter) && !(counter%2)) { all_led_on(); milisecdelay(300); all_led_off(); milisecdelay(700); } else { milisecdelay(1000); } }
int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { printf("Resetting the board..."); milisecdelay(500); full_reset(); /* After full chip reset we should not reach next step... */ printf("\n## Error: RESET FAILED!\n"); return 0; }
static __inline__ int abortboot(int bootdelay){ char stopc; int abort = 0; #ifdef CONFIG_SILENT_CONSOLE if(gd->flags & GD_FLG_SILENT){ /* Restore serial console */ console_assign(stdout, "serial"); console_assign(stderr, "serial"); } #endif if(bootdelay > 0){ #ifdef CONFIG_MENUPROMPT printf(CONFIG_MENUPROMPT, bootdelay); #else printf("Hit any key to stop autoboot: %d ", bootdelay); #endif while((bootdelay > 0) && (!abort)){ int i; --bootdelay; /* delay 100 * 10ms */ for(i = 0; !abort && i < 100; ++i){ /* we got a key press */ if(tstc()){ stopc = getc(); #ifdef CONFIG_AUTOBOOT_STOP_CHAR if (stopc == CONFIG_AUTOBOOT_STOP_CHAR) { #else if (stopc != 0) { #endif abort = 1; bootdelay = 0; break; } } udelay(10000); } printf("\b\b%d ", bootdelay); } printf("\n\n"); } #ifdef CONFIG_SILENT_CONSOLE if(abort){ /* permanently enable normal console output */ gd->flags &= ~(GD_FLG_SILENT); } else if(gd->flags & GD_FLG_SILENT){ /* Restore silent console */ console_assign(stdout, "nulldev"); console_assign(stderr, "nulldev"); } #endif return(abort); } #endif /* CONFIG_BOOTDELAY >= 0 */ /****************************************************************************/ void main_loop(void){ #ifndef CFG_HUSH_PARSER static char lastcommand[CFG_CBSIZE] = { 0, }; int len; int rc = 1; int flag; #endif int counter = 0; #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) char *s; int bootdelay; #endif /* defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) */ #ifdef CFG_HUSH_PARSER u_boot_hush_start(); #endif #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) // get boot delay (seconds) s = getenv("bootdelay"); bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY; // get boot command s = getenv("bootcmd"); #if !defined(CONFIG_BOOTCOMMAND) #error "CONFIG_BOOTCOMMAND not defined!" #endif if(!s){ setenv("bootcmd", CONFIG_BOOTCOMMAND); } s = getenv("bootcmd"); // are we going to run web failsafe mode, U-Boot console, U-Boot netconsole or just boot command? if(reset_button_status()){ #ifdef CONFIG_SILENT_CONSOLE if(gd->flags & GD_FLG_SILENT){ /* Restore serial console */ console_assign(stdout, "serial"); console_assign(stderr, "serial"); } /* enable normal console output */ gd->flags &= ~(GD_FLG_SILENT); #endif // wait 0,5s milisecdelay(500); printf("Press reset button for at least:\n- %d sec. to run web failsafe mode\n- %d sec. to run U-Boot console\n- %d sec. to run U-Boot netconsole\n\n", CONFIG_DELAY_TO_AUTORUN_HTTPD, CONFIG_DELAY_TO_AUTORUN_CONSOLE, CONFIG_DELAY_TO_AUTORUN_NETCONSOLE); printf("Reset button is pressed for: %2d ", counter); while(reset_button_status()){ // LED ON and wait 0,15s all_led_on(); milisecdelay(150); // LED OFF and wait 0,85s all_led_off(); milisecdelay(850); counter++; // how long the button is pressed? printf("\b\b\b%2d ", counter); if(!reset_button_status()){ break; } if(counter >= CONFIG_MAX_BUTTON_PRESSING){ break; } } all_led_off(); if(counter > 0){ // run web failsafe mode if(counter >= CONFIG_DELAY_TO_AUTORUN_HTTPD && counter < CONFIG_DELAY_TO_AUTORUN_CONSOLE){ printf("\n\nButton was pressed for %d sec...\nHTTP server is starting for firmware update...\n\n", counter); NetLoopHttpd(); bootdelay = -1; } else if(counter >= CONFIG_DELAY_TO_AUTORUN_CONSOLE && counter < CONFIG_DELAY_TO_AUTORUN_NETCONSOLE){ printf("\n\nButton was pressed for %d sec...\nStarting U-Boot console...\n\n", counter); bootdelay = -1; } else if(counter >= CONFIG_DELAY_TO_AUTORUN_NETCONSOLE){ printf("\n\nButton was pressed for %d sec...\nStarting U-Boot netconsole...\n\n", counter); bootdelay = -1; run_command("startnc", 0); } else { printf("\n\n## Error: button wasn't pressed long enough!\nContinuing normal boot...\n\n"); } } else { printf("\n\n## Error: button wasn't pressed long enough!\nContinuing normal boot...\n\n"); } } if(bootdelay >= 0 && s && !abortboot(bootdelay)){ // try to boot #ifndef CFG_HUSH_PARSER run_command(s, 0); #else parse_string_outer(s, FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP); #endif // something goes wrong! printf("\n## Error: failed to execute 'bootcmd'!\nHTTP server is starting for firmware update...\n\n"); NetLoopHttpd(); } #endif /* CONFIG_BOOTDELAY */ /* * Main Loop for Monitor Command Processing */ #ifdef CFG_HUSH_PARSER parse_file_outer(); /* This point is never reached */ for (;;); #else for(;;){ len = readline(CFG_PROMPT); flag = 0; /* assume no special flags for now */ if(len > 0){ strcpy(lastcommand, console_buffer); } else if(len == 0){ flag |= CMD_FLAG_REPEAT; } if(len == -1){ puts("<INTERRUPT>\n"); } else { rc = run_command(lastcommand, flag); } if(rc <= 0){ /* invalid command or not repeatable, forget it */ lastcommand[0] = 0; } } #endif /* CFG_HUSH_PARSER */ } /****************************************************************************/ /* * Prompt for input and read a line. * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0, * time out when time goes past endtime (timebase time in ticks). * Return: number of read characters * -1 if break * -2 if timed out */ int readline(const char * const prompt){ char *p = console_buffer; int n = 0; /* buffer index */ int plen = 0; /* prompt length */ int col; /* output column cnt */ char c; /* print prompt */ if(prompt){ plen = strlen(prompt); puts(prompt); } col = plen; for(;;){ c = getc(); /* * Special character handling */ switch(c){ case '\r': /* Enter */ case '\n': *p = '\0'; puts("\r\n"); return(p - console_buffer); case '\0': /* nul */ continue; case 0x03: /* ^C - break */ console_buffer[0] = '\0'; /* discard input */ return(-1); case 0x15: /* ^U - erase line */ while(col > plen){ puts(erase_seq); --col; } p = console_buffer; n = 0; continue; case 0x17: /* ^W - erase word */ p = delete_char(console_buffer, p, &col, &n, plen); while((n > 0) && (*p != ' ')){ p = delete_char(console_buffer, p, &col, &n, plen); } continue; case 0x08: /* ^H - backspace */ case 0x7F: /* DEL - backspace */ p = delete_char(console_buffer, p, &col, &n, plen); continue; default: /* * Must be a normal character then */ if(n < CFG_CBSIZE - 2){ if(c == '\t'){ /* expand TABs */ puts(tab_seq + (col & 07)); col += 8 - (col & 07); } else { ++col; /* echo input */ putc(c); } *p++ = c; ++n; } else { /* Buffer full */ putc('\a'); } } } }