wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 24 | /* #define DEBUG */ |
| 25 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 26 | #include <common.h> |
| 27 | #include <watchdog.h> |
| 28 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 29 | #include <malloc.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 30 | |
| 31 | #ifdef CFG_HUSH_PARSER |
| 32 | #include <hush.h> |
| 33 | #endif |
| 34 | |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 35 | #include <post.h> |
| 36 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 37 | #if defined(CONFIG_BOOT_RETRY_TIME) && defined(CONFIG_RESET_TO_RETRY) |
| 38 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /* for do_reset() prototype */ |
| 39 | #endif |
| 40 | |
| 41 | extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 42 | |
| 43 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 44 | #define MAX_DELAY_STOP_STR 32 |
| 45 | |
| 46 | static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen); |
| 47 | static int parse_line (char *, char *[]); |
| 48 | #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) |
| 49 | static int abortboot(int); |
| 50 | #endif |
| 51 | |
| 52 | #undef DEBUG_PARSER |
| 53 | |
| 54 | char console_buffer[CFG_CBSIZE]; /* console I/O buffer */ |
| 55 | |
| 56 | static char erase_seq[] = "\b \b"; /* erase sequence */ |
| 57 | static char tab_seq[] = " "; /* used to expand TABs */ |
| 58 | |
| 59 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 60 | static uint64_t endtime = 0; /* must be set, default is instant timeout */ |
| 61 | static int retry_time = -1; /* -1 so can call readline before main_loop */ |
| 62 | #endif |
| 63 | |
| 64 | #define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk()) |
| 65 | |
| 66 | #ifndef CONFIG_BOOT_RETRY_MIN |
| 67 | #define CONFIG_BOOT_RETRY_MIN CONFIG_BOOT_RETRY_TIME |
| 68 | #endif |
| 69 | |
| 70 | #ifdef CONFIG_MODEM_SUPPORT |
| 71 | int do_mdm_init = 0; |
| 72 | extern void mdm_init(void); /* defined in board.c */ |
| 73 | #endif |
| 74 | |
| 75 | /*************************************************************************** |
| 76 | * Watch for 'delay' seconds for autoboot stop or autoboot delay string. |
| 77 | * returns: 0 - no key string, allow autoboot |
| 78 | * 1 - got key string, abort |
| 79 | */ |
| 80 | #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) |
| 81 | # if defined(CONFIG_AUTOBOOT_KEYED) |
| 82 | static __inline__ int abortboot(int bootdelay) |
| 83 | { |
| 84 | int abort = 0; |
| 85 | uint64_t etime = endtick(bootdelay); |
| 86 | struct |
| 87 | { |
| 88 | char* str; |
| 89 | u_int len; |
| 90 | int retry; |
| 91 | } |
| 92 | delaykey [] = |
| 93 | { |
| 94 | { str: getenv ("bootdelaykey"), retry: 1 }, |
| 95 | { str: getenv ("bootdelaykey2"), retry: 1 }, |
| 96 | { str: getenv ("bootstopkey"), retry: 0 }, |
| 97 | { str: getenv ("bootstopkey2"), retry: 0 }, |
| 98 | }; |
| 99 | |
| 100 | char presskey [MAX_DELAY_STOP_STR]; |
| 101 | u_int presskey_len = 0; |
| 102 | u_int presskey_max = 0; |
| 103 | u_int i; |
| 104 | |
dzu | 8cb8143 | 2003-10-24 13:14:45 +0000 | [diff] [blame] | 105 | #ifdef CONFIG_SILENT_CONSOLE |
| 106 | { |
| 107 | DECLARE_GLOBAL_DATA_PTR; |
| 108 | |
| 109 | if (gd->flags & GD_FLG_SILENT) { |
| 110 | /* Restore serial console */ |
| 111 | console_assign (stdout, "serial"); |
| 112 | console_assign (stderr, "serial"); |
| 113 | } |
| 114 | } |
| 115 | #endif |
| 116 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 117 | # ifdef CONFIG_AUTOBOOT_PROMPT |
| 118 | printf (CONFIG_AUTOBOOT_PROMPT, bootdelay); |
| 119 | # endif |
| 120 | |
| 121 | # ifdef CONFIG_AUTOBOOT_DELAY_STR |
| 122 | if (delaykey[0].str == NULL) |
| 123 | delaykey[0].str = CONFIG_AUTOBOOT_DELAY_STR; |
| 124 | # endif |
| 125 | # ifdef CONFIG_AUTOBOOT_DELAY_STR2 |
| 126 | if (delaykey[1].str == NULL) |
| 127 | delaykey[1].str = CONFIG_AUTOBOOT_DELAY_STR2; |
| 128 | # endif |
| 129 | # ifdef CONFIG_AUTOBOOT_STOP_STR |
| 130 | if (delaykey[2].str == NULL) |
| 131 | delaykey[2].str = CONFIG_AUTOBOOT_STOP_STR; |
| 132 | # endif |
| 133 | # ifdef CONFIG_AUTOBOOT_STOP_STR2 |
| 134 | if (delaykey[3].str == NULL) |
| 135 | delaykey[3].str = CONFIG_AUTOBOOT_STOP_STR2; |
| 136 | # endif |
| 137 | |
| 138 | for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i ++) { |
| 139 | delaykey[i].len = delaykey[i].str == NULL ? |
| 140 | 0 : strlen (delaykey[i].str); |
| 141 | delaykey[i].len = delaykey[i].len > MAX_DELAY_STOP_STR ? |
| 142 | MAX_DELAY_STOP_STR : delaykey[i].len; |
| 143 | |
| 144 | presskey_max = presskey_max > delaykey[i].len ? |
| 145 | presskey_max : delaykey[i].len; |
| 146 | |
| 147 | # if DEBUG_BOOTKEYS |
| 148 | printf("%s key:<%s>\n", |
| 149 | delaykey[i].retry ? "delay" : "stop", |
| 150 | delaykey[i].str ? delaykey[i].str : "NULL"); |
| 151 | # endif |
| 152 | } |
| 153 | |
| 154 | /* In order to keep up with incoming data, check timeout only |
| 155 | * when catch up. |
| 156 | */ |
| 157 | while (!abort && get_ticks() <= etime) { |
| 158 | for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i ++) { |
| 159 | if (delaykey[i].len > 0 && |
| 160 | presskey_len >= delaykey[i].len && |
| 161 | memcmp (presskey + presskey_len - delaykey[i].len, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 162 | delaykey[i].str, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 163 | delaykey[i].len) == 0) { |
| 164 | # if DEBUG_BOOTKEYS |
| 165 | printf("got %skey\n", |
| 166 | delaykey[i].retry ? "delay" : "stop"); |
| 167 | # endif |
| 168 | |
| 169 | # ifdef CONFIG_BOOT_RETRY_TIME |
| 170 | /* don't retry auto boot */ |
| 171 | if (! delaykey[i].retry) |
| 172 | retry_time = -1; |
| 173 | # endif |
| 174 | abort = 1; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | if (tstc()) { |
| 179 | if (presskey_len < presskey_max) { |
| 180 | presskey [presskey_len ++] = getc(); |
| 181 | } |
| 182 | else { |
| 183 | for (i = 0; i < presskey_max - 1; i ++) |
| 184 | presskey [i] = presskey [i + 1]; |
| 185 | |
| 186 | presskey [i] = getc(); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | # if DEBUG_BOOTKEYS |
| 191 | if (!abort) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 192 | puts ("key timeout\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 193 | # endif |
| 194 | |
dzu | 8cb8143 | 2003-10-24 13:14:45 +0000 | [diff] [blame] | 195 | #ifdef CONFIG_SILENT_CONSOLE |
| 196 | { |
| 197 | DECLARE_GLOBAL_DATA_PTR; |
| 198 | |
| 199 | if (abort) { |
| 200 | /* permanently enable normal console output */ |
| 201 | gd->flags &= ~(GD_FLG_SILENT); |
| 202 | } else if (gd->flags & GD_FLG_SILENT) { |
| 203 | /* Restore silent console */ |
| 204 | console_assign (stdout, "nulldev"); |
| 205 | console_assign (stderr, "nulldev"); |
| 206 | } |
| 207 | } |
| 208 | #endif |
| 209 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 210 | return abort; |
| 211 | } |
| 212 | |
| 213 | # else /* !defined(CONFIG_AUTOBOOT_KEYED) */ |
| 214 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 215 | #ifdef CONFIG_MENUKEY |
| 216 | static int menukey = 0; |
| 217 | #endif |
| 218 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 219 | static __inline__ int abortboot(int bootdelay) |
| 220 | { |
| 221 | int abort = 0; |
| 222 | |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 223 | #ifdef CONFIG_SILENT_CONSOLE |
| 224 | { |
| 225 | DECLARE_GLOBAL_DATA_PTR; |
| 226 | |
| 227 | if (gd->flags & GD_FLG_SILENT) { |
| 228 | /* Restore serial console */ |
| 229 | console_assign (stdout, "serial"); |
| 230 | console_assign (stderr, "serial"); |
| 231 | } |
| 232 | } |
| 233 | #endif |
| 234 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 235 | #ifdef CONFIG_MENUPROMPT |
| 236 | printf(CONFIG_MENUPROMPT, bootdelay); |
| 237 | #else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 238 | printf("Hit any key to stop autoboot: %2d ", bootdelay); |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 239 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 240 | |
| 241 | #if defined CONFIG_ZERO_BOOTDELAY_CHECK |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 242 | /* |
| 243 | * Check if key already pressed |
| 244 | * Don't check if bootdelay < 0 |
| 245 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 246 | if (bootdelay >= 0) { |
| 247 | if (tstc()) { /* we got a key press */ |
| 248 | (void) getc(); /* consume input */ |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 249 | puts ("\b\b\b 0"); |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 250 | abort = 1; /* don't auto boot */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 251 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 252 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 253 | #endif |
| 254 | |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 255 | while ((bootdelay > 0) && (!abort)) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 256 | int i; |
| 257 | |
| 258 | --bootdelay; |
| 259 | /* delay 100 * 10ms */ |
| 260 | for (i=0; !abort && i<100; ++i) { |
| 261 | if (tstc()) { /* we got a key press */ |
| 262 | abort = 1; /* don't auto boot */ |
| 263 | bootdelay = 0; /* no more delay */ |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 264 | # ifdef CONFIG_MENUKEY |
| 265 | menukey = getc(); |
| 266 | # else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 267 | (void) getc(); /* consume input */ |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 268 | # endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 269 | break; |
| 270 | } |
| 271 | udelay (10000); |
| 272 | } |
| 273 | |
| 274 | printf ("\b\b\b%2d ", bootdelay); |
| 275 | } |
| 276 | |
| 277 | putc ('\n'); |
| 278 | |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 279 | #ifdef CONFIG_SILENT_CONSOLE |
| 280 | { |
| 281 | DECLARE_GLOBAL_DATA_PTR; |
| 282 | |
| 283 | if (abort) { |
| 284 | /* permanently enable normal console output */ |
| 285 | gd->flags &= ~(GD_FLG_SILENT); |
| 286 | } else if (gd->flags & GD_FLG_SILENT) { |
| 287 | /* Restore silent console */ |
| 288 | console_assign (stdout, "nulldev"); |
| 289 | console_assign (stderr, "nulldev"); |
| 290 | } |
| 291 | } |
| 292 | #endif |
| 293 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 294 | return abort; |
| 295 | } |
| 296 | # endif /* CONFIG_AUTOBOOT_KEYED */ |
| 297 | #endif /* CONFIG_BOOTDELAY >= 0 */ |
| 298 | |
| 299 | /****************************************************************************/ |
| 300 | |
| 301 | void main_loop (void) |
| 302 | { |
| 303 | #ifndef CFG_HUSH_PARSER |
| 304 | static char lastcommand[CFG_CBSIZE] = { 0, }; |
| 305 | int len; |
| 306 | int rc = 1; |
| 307 | int flag; |
| 308 | #endif |
| 309 | |
| 310 | #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) |
| 311 | char *s; |
| 312 | int bootdelay; |
| 313 | #endif |
| 314 | #ifdef CONFIG_PREBOOT |
| 315 | char *p; |
| 316 | #endif |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 317 | #ifdef CONFIG_BOOTCOUNT_LIMIT |
| 318 | unsigned long bootcount = 0; |
| 319 | unsigned long bootlimit = 0; |
| 320 | char *bcs; |
| 321 | char bcs_set[16]; |
| 322 | #endif /* CONFIG_BOOTCOUNT_LIMIT */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 323 | |
| 324 | #if defined(CONFIG_VFD) && defined(VFD_TEST_LOGO) |
| 325 | ulong bmp = 0; /* default bitmap */ |
| 326 | extern int trab_vfd (ulong bitmap); |
| 327 | |
| 328 | #ifdef CONFIG_MODEM_SUPPORT |
| 329 | if (do_mdm_init) |
| 330 | bmp = 1; /* alternate bitmap */ |
| 331 | #endif |
| 332 | trab_vfd (bmp); |
| 333 | #endif /* CONFIG_VFD && VFD_TEST_LOGO */ |
| 334 | |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 335 | #ifdef CONFIG_BOOTCOUNT_LIMIT |
| 336 | bootcount = bootcount_load(); |
| 337 | bootcount++; |
| 338 | bootcount_store (bootcount); |
| 339 | sprintf (bcs_set, "%lu", bootcount); |
| 340 | setenv ("bootcount", bcs_set); |
| 341 | bcs = getenv ("bootlimit"); |
| 342 | bootlimit = bcs ? simple_strtoul (bcs, NULL, 10) : 0; |
| 343 | #endif /* CONFIG_BOOTCOUNT_LIMIT */ |
| 344 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 345 | #ifdef CONFIG_MODEM_SUPPORT |
| 346 | debug ("DEBUG: main_loop: do_mdm_init=%d\n", do_mdm_init); |
| 347 | if (do_mdm_init) { |
| 348 | uchar *str = strdup(getenv("mdm_cmd")); |
| 349 | setenv ("preboot", str); /* set or delete definition */ |
| 350 | if (str != NULL) |
| 351 | free (str); |
| 352 | mdm_init(); /* wait for modem connection */ |
| 353 | } |
| 354 | #endif /* CONFIG_MODEM_SUPPORT */ |
| 355 | |
stroese | 0587597 | 2003-04-04 15:44:49 +0000 | [diff] [blame] | 356 | #ifdef CONFIG_VERSION_VARIABLE |
| 357 | { |
| 358 | extern char version_string[]; |
stroese | 0587597 | 2003-04-04 15:44:49 +0000 | [diff] [blame] | 359 | |
stroese | 155cb01 | 2003-07-11 08:00:33 +0000 | [diff] [blame] | 360 | setenv ("ver", version_string); /* set version variable */ |
stroese | 0587597 | 2003-04-04 15:44:49 +0000 | [diff] [blame] | 361 | } |
| 362 | #endif /* CONFIG_VERSION_VARIABLE */ |
| 363 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 364 | #ifdef CFG_HUSH_PARSER |
| 365 | u_boot_hush_start (); |
| 366 | #endif |
| 367 | |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 368 | #ifdef CONFIG_AUTO_COMPLETE |
| 369 | install_auto_complete(); |
| 370 | #endif |
| 371 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 372 | #ifdef CONFIG_PREBOOT |
| 373 | if ((p = getenv ("preboot")) != NULL) { |
| 374 | # ifdef CONFIG_AUTOBOOT_KEYED |
| 375 | int prev = disable_ctrlc(1); /* disable Control C checking */ |
| 376 | # endif |
| 377 | |
| 378 | # ifndef CFG_HUSH_PARSER |
| 379 | run_command (p, 0); |
| 380 | # else |
| 381 | parse_string_outer(p, FLAG_PARSE_SEMICOLON | |
| 382 | FLAG_EXIT_FROM_LOOP); |
| 383 | # endif |
| 384 | |
| 385 | # ifdef CONFIG_AUTOBOOT_KEYED |
| 386 | disable_ctrlc(prev); /* restore Control C checking */ |
| 387 | # endif |
| 388 | } |
| 389 | #endif /* CONFIG_PREBOOT */ |
| 390 | |
| 391 | #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) |
| 392 | s = getenv ("bootdelay"); |
| 393 | bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY; |
| 394 | |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 395 | debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 396 | |
| 397 | # ifdef CONFIG_BOOT_RETRY_TIME |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 398 | init_cmd_timeout (); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 399 | # endif /* CONFIG_BOOT_RETRY_TIME */ |
| 400 | |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 401 | #ifdef CONFIG_BOOTCOUNT_LIMIT |
| 402 | if (bootlimit && (bootcount > bootlimit)) { |
| 403 | printf ("Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n", |
| 404 | (unsigned)bootlimit); |
| 405 | s = getenv ("altbootcmd"); |
| 406 | } |
| 407 | else |
| 408 | #endif /* CONFIG_BOOTCOUNT_LIMIT */ |
| 409 | s = getenv ("bootcmd"); |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 410 | |
| 411 | debug ("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>"); |
| 412 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 413 | if (bootdelay >= 0 && s && !abortboot (bootdelay)) { |
| 414 | # ifdef CONFIG_AUTOBOOT_KEYED |
| 415 | int prev = disable_ctrlc(1); /* disable Control C checking */ |
| 416 | # endif |
| 417 | |
| 418 | # ifndef CFG_HUSH_PARSER |
| 419 | run_command (s, 0); |
| 420 | # else |
| 421 | parse_string_outer(s, FLAG_PARSE_SEMICOLON | |
| 422 | FLAG_EXIT_FROM_LOOP); |
| 423 | # endif |
| 424 | |
| 425 | # ifdef CONFIG_AUTOBOOT_KEYED |
| 426 | disable_ctrlc(prev); /* restore Control C checking */ |
| 427 | # endif |
| 428 | } |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 429 | |
| 430 | # ifdef CONFIG_MENUKEY |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 431 | if (menukey == CONFIG_MENUKEY) { |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 432 | s = getenv("menucmd"); |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 433 | if (s) { |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 434 | # ifndef CFG_HUSH_PARSER |
| 435 | run_command (s, bd, 0); |
| 436 | # else |
| 437 | parse_string_outer(s, FLAG_PARSE_SEMICOLON | |
| 438 | FLAG_EXIT_FROM_LOOP); |
| 439 | # endif |
| 440 | } |
| 441 | } |
| 442 | #endif /* CONFIG_MENUKEY */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 443 | #endif /* CONFIG_BOOTDELAY */ |
| 444 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 445 | #ifdef CONFIG_AMIGAONEG3SE |
| 446 | { |
| 447 | extern void video_banner(void); |
| 448 | video_banner(); |
| 449 | } |
| 450 | #endif |
| 451 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 452 | /* |
| 453 | * Main Loop for Monitor Command Processing |
| 454 | */ |
| 455 | #ifdef CFG_HUSH_PARSER |
| 456 | parse_file_outer(); |
| 457 | /* This point is never reached */ |
| 458 | for (;;); |
| 459 | #else |
| 460 | for (;;) { |
| 461 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 462 | if (rc >= 0) { |
| 463 | /* Saw enough of a valid command to |
| 464 | * restart the timeout. |
| 465 | */ |
| 466 | reset_cmd_timeout(); |
| 467 | } |
| 468 | #endif |
| 469 | len = readline (CFG_PROMPT); |
| 470 | |
| 471 | flag = 0; /* assume no special flags for now */ |
| 472 | if (len > 0) |
| 473 | strcpy (lastcommand, console_buffer); |
| 474 | else if (len == 0) |
| 475 | flag |= CMD_FLAG_REPEAT; |
| 476 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 477 | else if (len == -2) { |
| 478 | /* -2 means timed out, retry autoboot |
| 479 | */ |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 480 | puts ("\nTimed out waiting for command\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 481 | # ifdef CONFIG_RESET_TO_RETRY |
| 482 | /* Reinit board to run initialization code again */ |
| 483 | do_reset (NULL, 0, 0, NULL); |
| 484 | # else |
| 485 | return; /* retry autoboot */ |
| 486 | # endif |
| 487 | } |
| 488 | #endif |
| 489 | |
| 490 | if (len == -1) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 491 | puts ("<INTERRUPT>\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 492 | else |
| 493 | rc = run_command (lastcommand, flag); |
| 494 | |
| 495 | if (rc <= 0) { |
| 496 | /* invalid command or not repeatable, forget it */ |
| 497 | lastcommand[0] = 0; |
| 498 | } |
| 499 | } |
| 500 | #endif /*CFG_HUSH_PARSER*/ |
| 501 | } |
| 502 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 503 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 504 | /*************************************************************************** |
| 505 | * initialise command line timeout |
| 506 | */ |
| 507 | void init_cmd_timeout(void) |
| 508 | { |
| 509 | char *s = getenv ("bootretry"); |
| 510 | |
| 511 | if (s != NULL) |
wdenk | b028f71 | 2003-12-07 21:39:28 +0000 | [diff] [blame] | 512 | retry_time = (int)simple_strtol(s, NULL, 10); |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 513 | else |
| 514 | retry_time = CONFIG_BOOT_RETRY_TIME; |
| 515 | |
| 516 | if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN) |
| 517 | retry_time = CONFIG_BOOT_RETRY_MIN; |
| 518 | } |
| 519 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 520 | /*************************************************************************** |
| 521 | * reset command line timeout to retry_time seconds |
| 522 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 523 | void reset_cmd_timeout(void) |
| 524 | { |
| 525 | endtime = endtick(retry_time); |
| 526 | } |
| 527 | #endif |
| 528 | |
| 529 | /****************************************************************************/ |
| 530 | |
| 531 | /* |
| 532 | * Prompt for input and read a line. |
| 533 | * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0, |
| 534 | * time out when time goes past endtime (timebase time in ticks). |
| 535 | * Return: number of read characters |
| 536 | * -1 if break |
| 537 | * -2 if timed out |
| 538 | */ |
| 539 | int readline (const char *const prompt) |
| 540 | { |
| 541 | char *p = console_buffer; |
| 542 | int n = 0; /* buffer index */ |
| 543 | int plen = 0; /* prompt length */ |
| 544 | int col; /* output column cnt */ |
| 545 | char c; |
| 546 | |
| 547 | /* print prompt */ |
| 548 | if (prompt) { |
| 549 | plen = strlen (prompt); |
| 550 | puts (prompt); |
| 551 | } |
| 552 | col = plen; |
| 553 | |
| 554 | for (;;) { |
| 555 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 556 | while (!tstc()) { /* while no incoming data */ |
| 557 | if (retry_time >= 0 && get_ticks() > endtime) |
| 558 | return (-2); /* timed out */ |
| 559 | } |
| 560 | #endif |
| 561 | WATCHDOG_RESET(); /* Trigger watchdog, if needed */ |
| 562 | |
| 563 | #ifdef CONFIG_SHOW_ACTIVITY |
| 564 | while (!tstc()) { |
| 565 | extern void show_activity(int arg); |
| 566 | show_activity(0); |
| 567 | } |
| 568 | #endif |
| 569 | c = getc(); |
| 570 | |
| 571 | /* |
| 572 | * Special character handling |
| 573 | */ |
| 574 | switch (c) { |
| 575 | case '\r': /* Enter */ |
| 576 | case '\n': |
| 577 | *p = '\0'; |
| 578 | puts ("\r\n"); |
| 579 | return (p - console_buffer); |
| 580 | |
wdenk | 27aa818 | 2004-03-23 22:37:33 +0000 | [diff] [blame] | 581 | case '\0': /* nul */ |
| 582 | continue; |
| 583 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 584 | case 0x03: /* ^C - break */ |
| 585 | console_buffer[0] = '\0'; /* discard input */ |
| 586 | return (-1); |
| 587 | |
| 588 | case 0x15: /* ^U - erase line */ |
| 589 | while (col > plen) { |
| 590 | puts (erase_seq); |
| 591 | --col; |
| 592 | } |
| 593 | p = console_buffer; |
| 594 | n = 0; |
| 595 | continue; |
| 596 | |
| 597 | case 0x17: /* ^W - erase word */ |
| 598 | p=delete_char(console_buffer, p, &col, &n, plen); |
| 599 | while ((n > 0) && (*p != ' ')) { |
| 600 | p=delete_char(console_buffer, p, &col, &n, plen); |
| 601 | } |
| 602 | continue; |
| 603 | |
| 604 | case 0x08: /* ^H - backspace */ |
| 605 | case 0x7F: /* DEL - backspace */ |
| 606 | p=delete_char(console_buffer, p, &col, &n, plen); |
| 607 | continue; |
| 608 | |
| 609 | default: |
| 610 | /* |
| 611 | * Must be a normal character then |
| 612 | */ |
| 613 | if (n < CFG_CBSIZE-2) { |
| 614 | if (c == '\t') { /* expand TABs */ |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 615 | #ifdef CONFIG_AUTO_COMPLETE |
| 616 | /* if auto completion triggered just continue */ |
| 617 | *p = '\0'; |
| 618 | if (cmd_auto_complete(prompt, console_buffer, &n, &col)) { |
| 619 | p = console_buffer + n; /* reset */ |
| 620 | continue; |
| 621 | } |
| 622 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 623 | puts (tab_seq+(col&07)); |
| 624 | col += 8 - (col&07); |
| 625 | } else { |
| 626 | ++col; /* echo input */ |
| 627 | putc (c); |
| 628 | } |
| 629 | *p++ = c; |
| 630 | ++n; |
| 631 | } else { /* Buffer full */ |
| 632 | putc ('\a'); |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | /****************************************************************************/ |
| 639 | |
| 640 | static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen) |
| 641 | { |
| 642 | char *s; |
| 643 | |
| 644 | if (*np == 0) { |
| 645 | return (p); |
| 646 | } |
| 647 | |
| 648 | if (*(--p) == '\t') { /* will retype the whole line */ |
| 649 | while (*colp > plen) { |
| 650 | puts (erase_seq); |
| 651 | (*colp)--; |
| 652 | } |
| 653 | for (s=buffer; s<p; ++s) { |
| 654 | if (*s == '\t') { |
| 655 | puts (tab_seq+((*colp) & 07)); |
| 656 | *colp += 8 - ((*colp) & 07); |
| 657 | } else { |
| 658 | ++(*colp); |
| 659 | putc (*s); |
| 660 | } |
| 661 | } |
| 662 | } else { |
| 663 | puts (erase_seq); |
| 664 | (*colp)--; |
| 665 | } |
| 666 | (*np)--; |
| 667 | return (p); |
| 668 | } |
| 669 | |
| 670 | /****************************************************************************/ |
| 671 | |
| 672 | int parse_line (char *line, char *argv[]) |
| 673 | { |
| 674 | int nargs = 0; |
| 675 | |
| 676 | #ifdef DEBUG_PARSER |
| 677 | printf ("parse_line: \"%s\"\n", line); |
| 678 | #endif |
| 679 | while (nargs < CFG_MAXARGS) { |
| 680 | |
| 681 | /* skip any white space */ |
| 682 | while ((*line == ' ') || (*line == '\t')) { |
| 683 | ++line; |
| 684 | } |
| 685 | |
| 686 | if (*line == '\0') { /* end of line, no more args */ |
| 687 | argv[nargs] = NULL; |
| 688 | #ifdef DEBUG_PARSER |
| 689 | printf ("parse_line: nargs=%d\n", nargs); |
| 690 | #endif |
| 691 | return (nargs); |
| 692 | } |
| 693 | |
| 694 | argv[nargs++] = line; /* begin of argument string */ |
| 695 | |
| 696 | /* find end of string */ |
| 697 | while (*line && (*line != ' ') && (*line != '\t')) { |
| 698 | ++line; |
| 699 | } |
| 700 | |
| 701 | if (*line == '\0') { /* end of line, no more args */ |
| 702 | argv[nargs] = NULL; |
| 703 | #ifdef DEBUG_PARSER |
| 704 | printf ("parse_line: nargs=%d\n", nargs); |
| 705 | #endif |
| 706 | return (nargs); |
| 707 | } |
| 708 | |
| 709 | *line++ = '\0'; /* terminate current arg */ |
| 710 | } |
| 711 | |
| 712 | printf ("** Too many args (max. %d) **\n", CFG_MAXARGS); |
| 713 | |
| 714 | #ifdef DEBUG_PARSER |
| 715 | printf ("parse_line: nargs=%d\n", nargs); |
| 716 | #endif |
| 717 | return (nargs); |
| 718 | } |
| 719 | |
| 720 | /****************************************************************************/ |
| 721 | |
| 722 | static void process_macros (const char *input, char *output) |
| 723 | { |
| 724 | char c, prev; |
| 725 | const char *varname_start = NULL; |
| 726 | int inputcnt = strlen (input); |
| 727 | int outputcnt = CFG_CBSIZE; |
| 728 | int state = 0; /* 0 = waiting for '$' */ |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 729 | /* 1 = waiting for '(' or '{' */ |
| 730 | /* 2 = waiting for ')' or '}' */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 731 | /* 3 = waiting for ''' */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 732 | #ifdef DEBUG_PARSER |
| 733 | char *output_start = output; |
| 734 | |
| 735 | printf ("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", strlen(input), input); |
| 736 | #endif |
| 737 | |
| 738 | prev = '\0'; /* previous character */ |
| 739 | |
| 740 | while (inputcnt && outputcnt) { |
| 741 | c = *input++; |
| 742 | inputcnt--; |
| 743 | |
wdenk | a25f862 | 2003-01-02 23:57:29 +0000 | [diff] [blame] | 744 | if (state!=3) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 745 | /* remove one level of escape characters */ |
| 746 | if ((c == '\\') && (prev != '\\')) { |
| 747 | if (inputcnt-- == 0) |
| 748 | break; |
| 749 | prev = c; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 750 | c = *input++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 751 | } |
wdenk | a25f862 | 2003-01-02 23:57:29 +0000 | [diff] [blame] | 752 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 753 | |
| 754 | switch (state) { |
| 755 | case 0: /* Waiting for (unescaped) $ */ |
wdenk | a25f862 | 2003-01-02 23:57:29 +0000 | [diff] [blame] | 756 | if ((c == '\'') && (prev != '\\')) { |
| 757 | state = 3; |
wdenk | a25f862 | 2003-01-02 23:57:29 +0000 | [diff] [blame] | 758 | break; |
| 759 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 760 | if ((c == '$') && (prev != '\\')) { |
| 761 | state++; |
| 762 | } else { |
| 763 | *(output++) = c; |
| 764 | outputcnt--; |
| 765 | } |
| 766 | break; |
| 767 | case 1: /* Waiting for ( */ |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 768 | if (c == '(' || c == '{') { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 769 | state++; |
| 770 | varname_start = input; |
| 771 | } else { |
| 772 | state = 0; |
| 773 | *(output++) = '$'; |
| 774 | outputcnt--; |
| 775 | |
| 776 | if (outputcnt) { |
| 777 | *(output++) = c; |
| 778 | outputcnt--; |
| 779 | } |
| 780 | } |
| 781 | break; |
| 782 | case 2: /* Waiting for ) */ |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 783 | if (c == ')' || c == '}') { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 784 | int i; |
| 785 | char envname[CFG_CBSIZE], *envval; |
| 786 | int envcnt = input-varname_start-1; /* Varname # of chars */ |
| 787 | |
| 788 | /* Get the varname */ |
| 789 | for (i = 0; i < envcnt; i++) { |
| 790 | envname[i] = varname_start[i]; |
| 791 | } |
| 792 | envname[i] = 0; |
| 793 | |
| 794 | /* Get its value */ |
| 795 | envval = getenv (envname); |
| 796 | |
| 797 | /* Copy into the line if it exists */ |
| 798 | if (envval != NULL) |
| 799 | while ((*envval) && outputcnt) { |
| 800 | *(output++) = *(envval++); |
| 801 | outputcnt--; |
| 802 | } |
| 803 | /* Look for another '$' */ |
| 804 | state = 0; |
| 805 | } |
| 806 | break; |
wdenk | a25f862 | 2003-01-02 23:57:29 +0000 | [diff] [blame] | 807 | case 3: /* Waiting for ' */ |
| 808 | if ((c == '\'') && (prev != '\\')) { |
| 809 | state = 0; |
wdenk | a25f862 | 2003-01-02 23:57:29 +0000 | [diff] [blame] | 810 | } else { |
| 811 | *(output++) = c; |
| 812 | outputcnt--; |
| 813 | } |
| 814 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 815 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 816 | prev = c; |
| 817 | } |
| 818 | |
| 819 | if (outputcnt) |
| 820 | *output = 0; |
| 821 | |
| 822 | #ifdef DEBUG_PARSER |
| 823 | printf ("[PROCESS_MACROS] OUTPUT len %d: \"%s\"\n", |
| 824 | strlen(output_start), output_start); |
| 825 | #endif |
| 826 | } |
| 827 | |
| 828 | /**************************************************************************** |
| 829 | * returns: |
| 830 | * 1 - command executed, repeatable |
| 831 | * 0 - command executed but not repeatable, interrupted commands are |
| 832 | * always considered not repeatable |
| 833 | * -1 - not executed (unrecognized, bootd recursion or too many args) |
| 834 | * (If cmd is NULL or "" or longer than CFG_CBSIZE-1 it is |
| 835 | * considered unrecognized) |
| 836 | * |
| 837 | * WARNING: |
| 838 | * |
| 839 | * We must create a temporary copy of the command since the command we get |
| 840 | * may be the result from getenv(), which returns a pointer directly to |
| 841 | * the environment data, which may change magicly when the command we run |
| 842 | * creates or modifies environment variables (like "bootp" does). |
| 843 | */ |
| 844 | |
| 845 | int run_command (const char *cmd, int flag) |
| 846 | { |
| 847 | cmd_tbl_t *cmdtp; |
| 848 | char cmdbuf[CFG_CBSIZE]; /* working copy of cmd */ |
| 849 | char *token; /* start of token in cmdbuf */ |
| 850 | char *sep; /* end of token (separator) in cmdbuf */ |
| 851 | char finaltoken[CFG_CBSIZE]; |
| 852 | char *str = cmdbuf; |
| 853 | char *argv[CFG_MAXARGS + 1]; /* NULL terminated */ |
wdenk | f07771c | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 854 | int argc, inquotes; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 855 | int repeatable = 1; |
wdenk | f07771c | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 856 | int rc = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 857 | |
| 858 | #ifdef DEBUG_PARSER |
| 859 | printf ("[RUN_COMMAND] cmd[%p]=\"", cmd); |
| 860 | puts (cmd ? cmd : "NULL"); /* use puts - string may be loooong */ |
| 861 | puts ("\"\n"); |
| 862 | #endif |
| 863 | |
| 864 | clear_ctrlc(); /* forget any previous Control C */ |
| 865 | |
| 866 | if (!cmd || !*cmd) { |
| 867 | return -1; /* empty command */ |
| 868 | } |
| 869 | |
| 870 | if (strlen(cmd) >= CFG_CBSIZE) { |
| 871 | puts ("## Command too long!\n"); |
| 872 | return -1; |
| 873 | } |
| 874 | |
| 875 | strcpy (cmdbuf, cmd); |
| 876 | |
| 877 | /* Process separators and check for invalid |
| 878 | * repeatable commands |
| 879 | */ |
| 880 | |
| 881 | #ifdef DEBUG_PARSER |
| 882 | printf ("[PROCESS_SEPARATORS] %s\n", cmd); |
| 883 | #endif |
| 884 | while (*str) { |
| 885 | |
| 886 | /* |
| 887 | * Find separator, or string end |
| 888 | * Allow simple escape of ';' by writing "\;" |
| 889 | */ |
wdenk | a25f862 | 2003-01-02 23:57:29 +0000 | [diff] [blame] | 890 | for (inquotes = 0, sep = str; *sep; sep++) { |
| 891 | if ((*sep=='\'') && |
| 892 | (*(sep-1) != '\\')) |
| 893 | inquotes=!inquotes; |
| 894 | |
| 895 | if (!inquotes && |
| 896 | (*sep == ';') && /* separator */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 897 | ( sep != str) && /* past string start */ |
| 898 | (*(sep-1) != '\\')) /* and NOT escaped */ |
| 899 | break; |
| 900 | } |
| 901 | |
| 902 | /* |
| 903 | * Limit the token to data between separators |
| 904 | */ |
| 905 | token = str; |
| 906 | if (*sep) { |
| 907 | str = sep + 1; /* start of command for next pass */ |
| 908 | *sep = '\0'; |
| 909 | } |
| 910 | else |
| 911 | str = sep; /* no more commands for next pass */ |
| 912 | #ifdef DEBUG_PARSER |
| 913 | printf ("token: \"%s\"\n", token); |
| 914 | #endif |
| 915 | |
| 916 | /* find macros in this token and replace them */ |
| 917 | process_macros (token, finaltoken); |
| 918 | |
| 919 | /* Extract arguments */ |
| 920 | argc = parse_line (finaltoken, argv); |
| 921 | |
| 922 | /* Look up command in command table */ |
| 923 | if ((cmdtp = find_cmd(argv[0])) == NULL) { |
| 924 | printf ("Unknown command '%s' - try 'help'\n", argv[0]); |
wdenk | f07771c | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 925 | rc = -1; /* give up after bad command */ |
| 926 | continue; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | /* found - check max args */ |
| 930 | if (argc > cmdtp->maxargs) { |
| 931 | printf ("Usage:\n%s\n", cmdtp->usage); |
wdenk | f07771c | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 932 | rc = -1; |
| 933 | continue; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | #if (CONFIG_COMMANDS & CFG_CMD_BOOTD) |
| 937 | /* avoid "bootd" recursion */ |
| 938 | if (cmdtp->cmd == do_bootd) { |
| 939 | #ifdef DEBUG_PARSER |
| 940 | printf ("[%s]\n", finaltoken); |
| 941 | #endif |
| 942 | if (flag & CMD_FLAG_BOOTD) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 943 | puts ("'bootd' recursion detected\n"); |
wdenk | f07771c | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 944 | rc = -1; |
| 945 | continue; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 946 | } |
| 947 | else |
| 948 | flag |= CMD_FLAG_BOOTD; |
| 949 | } |
| 950 | #endif /* CFG_CMD_BOOTD */ |
| 951 | |
| 952 | /* OK - call function to do the command */ |
| 953 | if ((cmdtp->cmd) (cmdtp, flag, argc, argv) != 0) { |
wdenk | f07771c | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 954 | rc = -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | repeatable &= cmdtp->repeatable; |
| 958 | |
| 959 | /* Did the user stop this? */ |
| 960 | if (had_ctrlc ()) |
| 961 | return 0; /* if stopped then not repeatable */ |
| 962 | } |
| 963 | |
wdenk | f07771c | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 964 | return rc ? rc : repeatable; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /****************************************************************************/ |
| 968 | |
| 969 | #if (CONFIG_COMMANDS & CFG_CMD_RUN) |
| 970 | int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 971 | { |
| 972 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 973 | |
| 974 | if (argc < 2) { |
| 975 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 976 | return 1; |
| 977 | } |
| 978 | |
| 979 | for (i=1; i<argc; ++i) { |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 980 | char *arg; |
| 981 | |
| 982 | if ((arg = getenv (argv[i])) == NULL) { |
| 983 | printf ("## Error: \"%s\" not defined\n", argv[i]); |
| 984 | return 1; |
| 985 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 986 | #ifndef CFG_HUSH_PARSER |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 987 | if (run_command (arg, flag) == -1) |
| 988 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 989 | #else |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 990 | if (parse_string_outer(arg, |
wdenk | 7aa7861 | 2003-05-03 15:50:43 +0000 | [diff] [blame] | 991 | FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0) |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 992 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 993 | #endif |
| 994 | } |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 995 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 996 | } |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 997 | #endif /* CFG_CMD_RUN */ |