static char awaitkey(unsigned long delay, int* error_p) { int i; if (delay == -1) { while (1) { if (tstc()) /* we got a key press */ return getc(); } } else { for (i = 0; i < delay; i++) { if (tstc()) /* we got a key press */ return getc(); udelay (10*1000); } } if (error_p) *error_p = -1; return 0; }
/* * @return :1 -- OK 0 -- Error */ static int Receive_Byte (u8 *c, ulong timeout) { #if 1 #define DELAY 20 unsigned long counter = 0; while (!tstc () && (counter < timeout * 1000 / DELAY)) { udelay (DELAY); counter++; } if (tstc ()) { *c = getc (); return 1; } return 0; #else unsigned long counter = 0; int data = 0; do { data = getc (); counter++; }while ((data < 0) && (counter < timeout)); if (counter < timeout) { *c = (u8)data; //printf(" %.2X", *c); return 1; } return 0; #endif }
int CYGACC_COMM_IF_GETC_TIMEOUT (char chan,char *c) { #define DELAY 20 unsigned long counter=0; while (!tstc() && (counter < xyzModem_CHAR_TIMEOUT*1000/DELAY)) { udelay(DELAY); counter++; } if (tstc()) { *c=getc(); return 1; } return 0; }
int hello_world (int argc, char *argv[]) { int i; /* Print the ABI version */ app_startup(argv); printf ("Example expects ABI version %d\n", XF_VERSION); printf ("Actual U-Boot ABI version %d\n", (int)get_version()); printf ("Hello World\n"); printf ("argc = %d\n", argc); for (i=0; i<=argc; ++i) { printf ("argv[%d] = \"%s\"\n", i, argv[i] ? argv[i] : "<NULL>"); } volatile unsigned long *GPIO_DATAIN_BOOTKEY = 0x48310038; volatile unsigned long *GPIO_OE_SYSLED4 = 0x49058034; volatile unsigned long *GPIO_DATAOUT_SYSLED4 = 0x4905803C; *GPIO_OE_SYSLED4 &= 0xffffffef; while(!tstc()) { if((*GPIO_DATAIN_BOOTKEY & 0x00000080) == 0) { printf ("Button NOT pushed: LED OFF\n"); *GPIO_DATAOUT_SYSLED4 |= 0x00000010; } else { printf ("Button pushed: LED ON\n"); *GPIO_DATAOUT_SYSLED4 &= 0xffffffef; } } printf ("Hit any key to exit ... "); while (!tstc()) ; /* consume input */ (void) getc(); printf ("\n\n"); return (0); }
int board_late_init(void) { /* enable 3V3 for LAN controller */ if (raise_ab8500_gpio26() >= 0) { /* Turn on FSMC device */ writel(0x1, 0x8000f000); writel(0x1, 0x8000f008); /* setup FSMC for LAN controler */ writel(0x305b, 0x80000000); /* run at the highest possible speed */ writel(0x01010210, 0x80000004); } else printf("error: can't raise GPIO26\n"); /* enable 3v6 for GBF chip */ if ((raise_ab8500_gpio16() < 0)) printf("error: cant' raise GPIO16\n"); /* empty UART RX FIFO */ while (tstc()) (void) getc(); return 0; }
/*! \return 1 if yes is pressed otherwise 1 */ int WaitForYesPressed( const char* szWhat, const char* szWhere ) { int iRes = 0; /** * From autoscript we shouldn't expect user's confirmations. * Assume yes is the correct answer here to avoid halting the script. */ if (RunningAutoScript) return 1; printf( "%s(y/n)", szWhat ); while( 1 ) { if( tstc() ) { char c = getc(); putc( c ); if( 'y' == c ) { iRes = 1; break; } else { eprintf( "\n%s aborted\n", szWhere ); break; } } } /* while( true ) */ printf( "\n" ); return iRes; }
int check_uart_input(void) { int c = 0; if(uboot_spare_head.boot_data.work_mode != WORK_MODE_BOOT) { return 0; } if(tstc()) { c = getc(); printf("0x%x\n", c); } else { puts("no key input\n"); } if(c == '2') { return -1; } else if(c == '3') { sunxi_key_init(); do_key_test(NULL, 0, 1, NULL); } else if(c == 's') //shell mode { gd->force_shell = 1; gd->debug_mode = 1; } return 0; }
static int read_opt(void) { /* wait for key to be pressed */ while (!tstc()) ; return getc(); }
int getc(void) { unsigned char ch; uint64_t start; /* * For 100us we read the characters from the serial driver * into a kfifo. This helps us not to lose characters * in small hardware fifos. */ start = get_time_ns(); while (1) { if (tstc()) { kfifo_putc(console_input_buffer, getc_raw()); start = get_time_ns(); } if (is_timeout(start, 100 * USECOND) && kfifo_len(console_input_buffer)) break; } kfifo_getc(console_input_buffer, &ch); return ch; }
static int do_vboot_twostop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { uint32_t selection; int ro_firmware; bootstage_mark_name(BOOTSTAGE_VBOOT_TWOSTOP, "do_vboot_twostop"); /* * Empty keyboard buffer before boot. In case EC did not clear its * buffer between power cycles, this prevents vboot of current power * cycle being affected by keystrokes of previous power cycle. */ while (tstc()) getc(); if (cros_init()) { VBDEBUG("fail to init cros library\n"); goto on_error; } /* * TODO: We should clear screen later if we load graphics optionally. * In normal mode, we don't need to load graphics driver and clear * screen. */ display_clear(); /* * A processor reset jumps to the reset entry point (which is the * read-only firmware), otherwise we have entered U-Boot from a * software jump. * * Note: If a read-only firmware is loaded to memory not because of a * processor reset, this instance of read-only firmware should go to the * readwrite firmware code path. */ ro_firmware = is_processor_reset(); VBDEBUG("Starting %s firmware\n", ro_firmware ? "read-only" : "read-write"); if (ro_firmware) selection = twostop_boot(0); else selection = twostop_readwrite_main_firmware(); VBDEBUG("selection of main firmware: %s\n", str_selection(selection)); if (selection == TWOSTOP_SELECT_COMMAND_LINE) return 0; if (selection == TWOSTOP_SELECT_POWER_OFF) power_off(); assert(selection == TWOSTOP_SELECT_ERROR); on_error: cold_reboot(); return 0; }
int hello_world (int argc, char * const argv[]) { int i; /* Print the ABI version */ app_startup(argv); printf ("Example expects ABI version %d\n", XF_VERSION); printf ("Actual U-Boot ABI version %d\n", (int)get_version()); printf ("Hello World\n"); printf ("argc = %d\n", argc); for (i=0; i<=argc; ++i) { printf ("argv[%d] = \"%s\"\n", i, argv[i] ? argv[i] : "<NULL>"); } printf ("Hit any key to exit ... "); while (!tstc()) ; /* consume input */ (void) getc(); printf ("\n\n"); return (0); }
void video_scroll(int rows) { unsigned short clear = ((unsigned short)current_attr) | (' '<<8); unsigned short* addr16 = &((unsigned short *)VIDEO_BASE)[(VIDEO_ROWS-rows)*VIDEO_COLS]; int i; char *s; s = getenv("vga_askscroll"); video_scrolls += rows; if (video_scrolls >= video_numrows) { if (s && strcmp(s, "yes")) { while (-1 == tstc()); } video_scrolls = 0; } memcpy(VIDEO_BASE, VIDEO_BASE+rows*(VIDEO_COLS*2), (VIDEO_ROWS-rows)*(VIDEO_COLS*2)); for (i = 0 ; i < rows * VIDEO_COLS ; i++) addr16[i] = clear; cursor_row-=rows; cursor_col=0; }
/* test if ctrl-c was pressed */ int ctrlc (void) { poller_call(); if (tstc() && getc() == 3) return 1; return 0; }
int comm_if_getc_tout(char *c) { unsigned long counter=0; #define DELAY 20 while(!tstc() && (counter < xyzModem_CHAR_TIMEOUT*1000/DELAY)){ udelay(DELAY); counter++; } if(tstc()){ *c=getc(); return 1; } return 0; }
static int CYGACC_COMM_IF_GETC_TIMEOUT (char chan, char *c) { ulong now = get_timer(0); while (!tstc ()) { if (get_timer(now) > xyzModem_CHAR_TIMEOUT) break; } if (tstc ()) { *c = getc (); return 1; } return 0; }
static __inline__ int abortboot(int bootdelay){ 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) && (getenv("silent") == NULL)){ #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()){ /* don't auto boot */ abort = 1; /* no more delay */ bootdelay = 0; /* consume input */ (void) getc(); 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); }
int bootretry_tstc_timeout(void) { while (!tstc()) { /* while no incoming data */ if (retry_time >= 0 && get_ticks() > endtime) return -ETIMEDOUT; WATCHDOG_RESET(); } return 0; }
/* * pseudo signature: * * int API_tstc(int *c) */ static int API_tstc(va_list ap) { int *t; if ((t = (int *)va_arg(ap, u_int32_t)) == NULL) return API_EINVAL; *t = tstc(); return 0; }
int ctrlc (void) { if (tstc()) { switch (getc ()) { case 0x03: /* ^C - Control C */ return 1; default: break; } } return 0; }
void do_printenv (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) { uchar *env, *nxt; int i; #if defined(CFG_FLASH_ENV_ADDR) uchar *environment = env_init(); #else env_init(); #endif /* CFG_FLASH_ENV_ADDR */ if (argc == 1) { /* Print all env variables */ uchar *start = environment; for (env=environment; *env; env=nxt+1) { for (nxt=env; *nxt; ++nxt) ; puts (env); putc ('\n'); if (tstc()) { getc (); printf ("\n ** Abort\n"); return; } } printf("\nEnvironment size: %d bytes\n", env-start); return; } for (i=1; i<argc; ++i) { /* print single env variables */ char *name = argv[i]; char *val = NULL; for (env=environment; *env; env=nxt+1) { for (nxt=env; *nxt; ++nxt) ; val=envmatch(name, env); if (val) { puts (name); putc ('='); puts (val); putc ('\n'); break; } } if (!val) printf ("## Error: \"%s\" not defined\n", name); } }
static int passwd_abort(uint64_t etime) { const char *sha_env_str = getenv("bootstopkeysha256"); u8 sha_env[SHA256_SUM_LEN]; u8 sha[SHA256_SUM_LEN]; char presskey[MAX_DELAY_STOP_STR]; const char *algo_name = "sha256"; u_int presskey_len = 0; int abort = 0; int size; int ret; if (sha_env_str == NULL) sha_env_str = CONFIG_AUTOBOOT_STOP_STR_SHA256; /* * Generate the binary value from the environment hash value * so that we can compare this value with the computed hash * from the user input */ ret = hash_parse_string(algo_name, sha_env_str, sha_env); if (ret) { printf("Hash %s not supported!\n", algo_name); return 0; } /* * We don't know how long the stop-string is, so we need to * generate the sha256 hash upon each input character and * compare the value with the one saved in the environment */ do { if (tstc()) { /* Check for input string overflow */ if (presskey_len >= MAX_DELAY_STOP_STR) return 0; presskey[presskey_len++] = getc(); /* Calculate sha256 upon each new char */ hash_block(algo_name, (const void *)presskey, presskey_len, sha, &size); /* And check if sha matches saved value in env */ if (slow_equals(sha, sha_env, SHA256_SUM_LEN)) abort = 1; } } while (!abort && get_ticks() <= etime); return abort; }
int wait_for_ch_timeout(int rel_timeout, uint64_t abs_timeout) { uint64_t etime = abs_timeout; if (rel_timeout) etime = endtick(rel_timeout); while (!tstc()) { /* while no incoming data */ if ((retry_time >= 0) && etime && (get_ticks() > etime)) return (-2); /* timed out */ WATCHDOG_RESET(); } return 0; }
int misc_init_r(void) { char *str; int mach_type; str = getenv("mach_type"); if (str != NULL) { mach_type = simple_strtoul(str, NULL, 10); printf("Overwriting MACH_TYPE with %d!!!\n", mach_type); gd->bd->bi_arch_number = mach_type; } #if defined(CONFIG_KM_MGCOGE3UN) char *wait_for_ne; wait_for_ne = getenv("waitforne"); if (wait_for_ne != NULL) { if (strcmp(wait_for_ne, "true") == 0) { int cnt = 0; int abort = 0; puts("NE go: "); while (startup_allowed() == 0) { if (tstc()) { (void) getc(); /* consume input */ abort = 1; break; } udelay(200000); cnt++; if (cnt == 5) puts("wait\b\b\b\b"); if (cnt == 10) { cnt = 0; puts(" \b\b\b\b"); } } if (abort == 1) printf("\nAbort waiting for ne\n"); else puts("OK\n"); } } #endif initialize_unit_leds(); set_km_env(); #if defined(CONFIG_BOOTCOUNT_LIMIT) set_bootcount_addr(); #endif return 0; }
int ctrlc(void) { if (!ctrlc_disabled && gd->have_console) { if (tstc()) { switch (getc()) { case 0x03: /* ^C - Control C */ ctrlc_was_pressed = 1; return 1; default: break; } } } return 0; }
int last_stage_init(void) { int i; #if CONFIG_NETPHONE_VERSION == 2 /* assert peripheral reset */ ((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat &= ~_BW(12); for (i = 0; i < 10; i++) udelay(1000); ((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat |= _BW(12); #endif reset_phys(); /* check in order to enable the local console */ left_to_poll = PHONE_CONSOLE_POLL_HZ; i = CONFIG_SYS_HZ * 2; while (i > 0) { if (tstc()) { getc(); break; } do_poll(); if (drv_phone_use_me()) { status_led_set(0, STATUS_LED_ON); while (!drv_phone_is_idle()) { do_poll(); udelay(1000000 / CONFIG_SYS_HZ); } console_assign(stdin, "phone"); console_assign(stdout, "phone"); console_assign(stderr, "phone"); setenv("bootdelay", "-1"); break; } udelay(1000000 / CONFIG_SYS_HZ); i--; left_to_poll--; } left_to_poll = PHONE_CONSOLE_POLL_HZ; return 0; }
int hello_world (int argc, char *argv[]) { app_startup(argv); printf ("Toggle SYSLED_4 using BOOT_KEY\n"); // Initialize pointers volatile unsigned long* GPIO_DATAIN_BOOTKEY = 0x48310038; volatile unsigned long* GPIO_OE_SYSLED4 = 0x49058034; volatile unsigned long* GPIO_DATAOUT_SYSLED4 = 0x4905803c; // Setup output for SYSLED4 *GPIO_OE_SYSLED4 &= 0xffffffef; // Continues loop checking BOOT_KEY and updating SYSLED: printf ("Hit any key to exit ... \n\n"); long bootKeyLast = 0; while(!tstc()) { if (*GPIO_DATAIN_BOOTKEY != bootKeyLast) { if (*GPIO_DATAIN_BOOTKEY & 128) printf ("%s", "SysLED4 is on!\n"); else printf ("%s", "SysLED4 is off!\n"); bootKeyLast = *GPIO_DATAIN_BOOTKEY; } if (*GPIO_DATAIN_BOOTKEY & 128) { *GPIO_DATAOUT_SYSLED4 &= 0xffffffef; } else { *GPIO_DATAOUT_SYSLED4 |= 16; } } // consume input (void) getc(); printf ("\n\n"); return (0); }
/** * getline - consume a line of input and handle some escape sequences */ static char *getline(void) { static char buffer[100]; char c; size_t i; i = 0; while (1) { buffer[i] = '\0'; while (!tstc()) continue; c = getc(); /* Convert to uppercase */ if (c >= 'a' && c <= 'z') c -= ('a' - 'A'); switch (c) { case '\r': /* Enter/Return key */ case '\n': puts("\n"); return buffer; case 0x03: /* ^C - break */ return NULL; case 0x5F: case 0x08: /* ^H - backspace */ case 0x7F: /* DEL - backspace */ if (i) { puts("\b \b"); i--; } break; default: /* Ignore control characters */ if (c < 0x20) break; /* Queue up all other characters */ buffer[i++] = c; printf("%c", c); break; } } }
static int do_load_serial(struct command *cmdtp, int argc, char *argv[]) { ulong offset = 0; ulong addr; int i; const char *env_echo; int rcode = 0; if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) { do_echo = 1; } else { do_echo = 0; } if (argc == 2) { offset = simple_strtoul(argv[1], NULL, 16); } printf ("## Ready for S-Record download ...\n"); addr = load_serial(offset); /* * Gather any trailing characters (for instance, the ^D which * is sent by 'cu' after sending a file), and give the * box some time (100 * 1 ms) */ for (i=0; i<100; ++i) { if (tstc()) { (void) getc(); } udelay(1000); } if (addr == ~0) { printf("## S-Record download aborted\n"); rcode = 1; } else { printf("## Start Addr = 0x%08lX\n", addr); } return rcode; }
int misc_init_r(void) { #if defined(CONFIG_KM_MGCOGE3UN) char *wait_for_ne; u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE); wait_for_ne = env_get("waitforne"); if ((wait_for_ne != NULL) && (dip_switch == 0)) { if (strcmp(wait_for_ne, "true") == 0) { int cnt = 0; int abort = 0; puts("NE go: "); while (startup_allowed() == 0) { if (tstc()) { (void) getc(); /* consume input */ abort = 1; break; } udelay(200000); cnt++; if (cnt == 5) puts("wait\b\b\b\b"); if (cnt == 10) { cnt = 0; puts(" \b\b\b\b"); } } if (abort == 1) printf("\nAbort waiting for ne\n"); else puts("OK\n"); } } #endif ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN); initialize_unit_leds(); set_km_env(); set_bootcount_addr(); return 0; }
int console_countdown(int timeout_s, unsigned flags, char *out_key) { uint64_t start, second; int countdown, ret = -EINTR; int key = 0; start = get_time_ns(); second = start; countdown = timeout_s; if (!(flags & CONSOLE_COUNTDOWN_SILENT)) printf("%2d", countdown--); do { if (tstc()) { key = getchar(); if (flags & CONSOLE_COUNTDOWN_ANYKEY) goto out; if (flags & CONSOLE_COUNTDOWN_RETURN && key == '\n') goto out; if (flags & CONSOLE_COUNTDOWN_CTRLC && key == 3) goto out; key = 0; } if (!(flags & CONSOLE_COUNTDOWN_SILENT) && is_timeout(second, SECOND)) { printf("\b\b%2d", countdown--); second += SECOND; } } while (!is_timeout(start, timeout_s * SECOND)); ret = 0; out: if (!(flags & CONSOLE_COUNTDOWN_SILENT)) printf("\n"); if (key && out_key) *out_key = key; return ret; }