X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Fmain.c;h=79ad2912a751c6097e524dca9b7224990f30fb96;hb=7f9f4347cf325c63a39fe30910f3fb211ae2cc15;hp=ad2a386c86586a62fc40bdcfaec530dd7576d107;hpb=694976afa5dcc5c4e7eaeaa0612eac35cd5bd8ec;p=oweals%2Fu-boot.git diff --git a/common/main.c b/common/main.c index ad2a386c86..79ad2912a7 100644 --- a/common/main.c +++ b/common/main.c @@ -40,7 +40,7 @@ #include -#ifdef CONFIG_SILENT_CONSOLE +#if defined(CONFIG_SILENT_CONSOLE) || defined(CONFIG_POST) || defined(CONFIG_CMDLINE_EDITING) DECLARE_GLOBAL_DATA_PTR; #endif @@ -67,11 +67,9 @@ static int abortboot(int); char console_buffer[CFG_CBSIZE]; /* console I/O buffer */ -#ifndef CONFIG_CMDLINE_EDITING static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen); static char erase_seq[] = "\b \b"; /* erase sequence */ static char tab_seq[] = " "; /* used to expand TABs */ -#endif /* CONFIG_CMDLINE_EDITING */ #ifdef CONFIG_BOOT_RETRY_TIME static uint64_t endtime = 0; /* must be set, default is instant timeout */ @@ -369,6 +367,12 @@ void main_loop (void) init_cmd_timeout (); # endif /* CONFIG_BOOT_RETRY_TIME */ +#ifdef CONFIG_POST + if (gd->flags & GD_FLG_POSTFAIL) { + s = getenv("failbootcmd"); + } + else +#endif /* CONFIG_POST */ #ifdef CONFIG_BOOTCOUNT_LIMIT if (bootlimit && (bootcount > bootlimit)) { printf ("Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n", @@ -505,7 +509,7 @@ void reset_cmd_timeout(void) */ #define putnstr(str,n) do { \ - printf ("%.*s", n, str); \ + printf ("%.*s", (int)n, str); \ } while (0) #define CTL_CH(c) ((c) - 'a' + 1) @@ -709,6 +713,13 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len) while (1) { rlen = 1; +#ifdef CONFIG_BOOT_RETRY_TIME + while (!tstc()) { /* while no incoming data */ + if (retry_time >= 0 && get_ticks() > endtime) + return (-2); /* timed out */ + } +#endif + ichar = getcmd_getch(); if ((ichar == '\n') || (ichar == '\r')) { @@ -924,22 +935,31 @@ int readline (const char *const prompt) int readline_into_buffer (const char *const prompt, char * buffer) { char *p = buffer; - char * p_buf = p; #ifdef CONFIG_CMDLINE_EDITING unsigned int len=MAX_CMDBUF_SIZE; int rc; static int initted = 0; - if (!initted) { - hist_init(); - initted = 1; - } + /* + * History uses a global array which is not + * writable until after relocation to RAM. + * Revert to non-history version if still + * running from flash. + */ + if (gd->flags & GD_FLG_RELOC) { + if (!initted) { + hist_init(); + initted = 1; + } - puts (prompt); + puts (prompt); - rc = cread_line(prompt, p, &len); - return rc < 0 ? rc : len; -#else + rc = cread_line(prompt, p, &len); + return rc < 0 ? rc : len; + + } else { +#endif /* CONFIG_CMDLINE_EDITING */ + char * p_buf = p; int n = 0; /* buffer index */ int plen = 0; /* prompt length */ int col; /* output column cnt */ @@ -1034,12 +1054,13 @@ int readline_into_buffer (const char *const prompt, char * buffer) } } } -#endif /* CONFIG_CMDLINE_EDITING */ +#ifdef CONFIG_CMDLINE_EDITING + } +#endif } /****************************************************************************/ -#ifndef CONFIG_CMDLINE_EDITING static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen) { char *s; @@ -1069,7 +1090,6 @@ static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen) (*np)--; return (p); } -#endif /* CONFIG_CMDLINE_EDITING */ /****************************************************************************/