main.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Add to readline cmdline-editing by
  6. * (C) Copyright 2005
  7. * JinHua Luo, GuangDong Linux Center, <luo.jinhua@gd-linux.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. /* #define DEBUG */
  28. #include <common.h>
  29. #include <watchdog.h>
  30. #include <command.h>
  31. #ifdef CONFIG_MODEM_SUPPORT
  32. #include <malloc.h> /* for free() prototype */
  33. #endif
  34. #ifdef CONFIG_SYS_HUSH_PARSER
  35. #include <hush.h>
  36. #endif
  37. #include <post.h>
  38. #if defined(CONFIG_SILENT_CONSOLE) || defined(CONFIG_POST) || defined(CONFIG_CMDLINE_EDITING)
  39. DECLARE_GLOBAL_DATA_PTR;
  40. #endif
  41. /*
  42. * Board-specific Platform code can reimplement show_boot_progress () if needed
  43. */
  44. void inline __show_boot_progress (int val) {}
  45. void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progress")));
  46. #if defined(CONFIG_BOOT_RETRY_TIME) && defined(CONFIG_RESET_TO_RETRY)
  47. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /* for do_reset() prototype */
  48. #endif
  49. extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  50. #if defined(CONFIG_UPDATE_TFTP)
  51. void update_tftp (void);
  52. #endif /* CONFIG_UPDATE_TFTP */
  53. #define MAX_DELAY_STOP_STR 32
  54. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  55. static int abortboot(int);
  56. #endif
  57. #undef DEBUG_PARSER
  58. char console_buffer[CONFIG_SYS_CBSIZE]; /* console I/O buffer */
  59. static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen);
  60. static char erase_seq[] = "\b \b"; /* erase sequence */
  61. static char tab_seq[] = " "; /* used to expand TABs */
  62. #ifdef CONFIG_BOOT_RETRY_TIME
  63. static uint64_t endtime = 0; /* must be set, default is instant timeout */
  64. static int retry_time = -1; /* -1 so can call readline before main_loop */
  65. #endif
  66. #define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk())
  67. #ifndef CONFIG_BOOT_RETRY_MIN
  68. #define CONFIG_BOOT_RETRY_MIN CONFIG_BOOT_RETRY_TIME
  69. #endif
  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. * Watch for 'delay' seconds for autoboot stop or autoboot delay string.
  76. * returns: 0 - no key string, allow autoboot
  77. * 1 - got key string, abort
  78. */
  79. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  80. # if defined(CONFIG_AUTOBOOT_KEYED)
  81. static __inline__ int abortboot(int bootdelay)
  82. {
  83. int abort = 0;
  84. uint64_t etime = endtick(bootdelay);
  85. struct {
  86. char* str;
  87. u_int len;
  88. int retry;
  89. }
  90. delaykey [] = {
  91. { str: getenv ("bootdelaykey"), retry: 1 },
  92. { str: getenv ("bootdelaykey2"), retry: 1 },
  93. { str: getenv ("bootstopkey"), retry: 0 },
  94. { str: getenv ("bootstopkey2"), retry: 0 },
  95. };
  96. char presskey [MAX_DELAY_STOP_STR];
  97. u_int presskey_len = 0;
  98. u_int presskey_max = 0;
  99. u_int i;
  100. # ifdef CONFIG_AUTOBOOT_PROMPT
  101. printf(CONFIG_AUTOBOOT_PROMPT);
  102. # endif
  103. # ifdef CONFIG_AUTOBOOT_DELAY_STR
  104. if (delaykey[0].str == NULL)
  105. delaykey[0].str = CONFIG_AUTOBOOT_DELAY_STR;
  106. # endif
  107. # ifdef CONFIG_AUTOBOOT_DELAY_STR2
  108. if (delaykey[1].str == NULL)
  109. delaykey[1].str = CONFIG_AUTOBOOT_DELAY_STR2;
  110. # endif
  111. # ifdef CONFIG_AUTOBOOT_STOP_STR
  112. if (delaykey[2].str == NULL)
  113. delaykey[2].str = CONFIG_AUTOBOOT_STOP_STR;
  114. # endif
  115. # ifdef CONFIG_AUTOBOOT_STOP_STR2
  116. if (delaykey[3].str == NULL)
  117. delaykey[3].str = CONFIG_AUTOBOOT_STOP_STR2;
  118. # endif
  119. for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
  120. delaykey[i].len = delaykey[i].str == NULL ?
  121. 0 : strlen (delaykey[i].str);
  122. delaykey[i].len = delaykey[i].len > MAX_DELAY_STOP_STR ?
  123. MAX_DELAY_STOP_STR : delaykey[i].len;
  124. presskey_max = presskey_max > delaykey[i].len ?
  125. presskey_max : delaykey[i].len;
  126. # if DEBUG_BOOTKEYS
  127. printf("%s key:<%s>\n",
  128. delaykey[i].retry ? "delay" : "stop",
  129. delaykey[i].str ? delaykey[i].str : "NULL");
  130. # endif
  131. }
  132. /* In order to keep up with incoming data, check timeout only
  133. * when catch up.
  134. */
  135. do {
  136. if (tstc()) {
  137. if (presskey_len < presskey_max) {
  138. presskey [presskey_len ++] = getc();
  139. }
  140. else {
  141. for (i = 0; i < presskey_max - 1; i ++)
  142. presskey [i] = presskey [i + 1];
  143. presskey [i] = getc();
  144. }
  145. }
  146. for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
  147. if (delaykey[i].len > 0 &&
  148. presskey_len >= delaykey[i].len &&
  149. memcmp (presskey + presskey_len - delaykey[i].len,
  150. delaykey[i].str,
  151. delaykey[i].len) == 0) {
  152. # if DEBUG_BOOTKEYS
  153. printf("got %skey\n",
  154. delaykey[i].retry ? "delay" : "stop");
  155. # endif
  156. # ifdef CONFIG_BOOT_RETRY_TIME
  157. /* don't retry auto boot */
  158. if (! delaykey[i].retry)
  159. retry_time = -1;
  160. # endif
  161. abort = 1;
  162. }
  163. }
  164. } while (!abort && get_ticks() <= etime);
  165. # if DEBUG_BOOTKEYS
  166. if (!abort)
  167. puts("key timeout\n");
  168. # endif
  169. #ifdef CONFIG_SILENT_CONSOLE
  170. if (abort)
  171. gd->flags &= ~GD_FLG_SILENT;
  172. #endif
  173. return abort;
  174. }
  175. # else /* !defined(CONFIG_AUTOBOOT_KEYED) */
  176. #ifdef CONFIG_MENUKEY
  177. static int menukey = 0;
  178. #endif
  179. static __inline__ int abortboot(int bootdelay)
  180. {
  181. int abort = 0;
  182. #ifdef CONFIG_MENUPROMPT
  183. printf(CONFIG_MENUPROMPT);
  184. #else
  185. printf("Hit any key to stop autoboot: %2d ", bootdelay);
  186. #endif
  187. #if defined CONFIG_ZERO_BOOTDELAY_CHECK
  188. /*
  189. * Check if key already pressed
  190. * Don't check if bootdelay < 0
  191. */
  192. if (bootdelay >= 0) {
  193. if (tstc()) { /* we got a key press */
  194. (void) getc(); /* consume input */
  195. puts ("\b\b\b 0");
  196. abort = 1; /* don't auto boot */
  197. }
  198. }
  199. #endif
  200. while ((bootdelay > 0) && (!abort)) {
  201. int i;
  202. --bootdelay;
  203. /* delay 100 * 10ms */
  204. for (i=0; !abort && i<100; ++i) {
  205. if (tstc()) { /* we got a key press */
  206. abort = 1; /* don't auto boot */
  207. bootdelay = 0; /* no more delay */
  208. # ifdef CONFIG_MENUKEY
  209. menukey = getc();
  210. # else
  211. (void) getc(); /* consume input */
  212. # endif
  213. break;
  214. }
  215. udelay(10000);
  216. }
  217. printf("\b\b\b%2d ", bootdelay);
  218. }
  219. putc('\n');
  220. #ifdef CONFIG_SILENT_CONSOLE
  221. if (abort)
  222. gd->flags &= ~GD_FLG_SILENT;
  223. #endif
  224. return abort;
  225. }
  226. # endif /* CONFIG_AUTOBOOT_KEYED */
  227. #endif /* CONFIG_BOOTDELAY >= 0 */
  228. /****************************************************************************/
  229. void main_loop (void)
  230. {
  231. #ifndef CONFIG_SYS_HUSH_PARSER
  232. static char lastcommand[CONFIG_SYS_CBSIZE] = { 0, };
  233. int len;
  234. int rc = 1;
  235. int flag;
  236. #endif
  237. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  238. char *s;
  239. int bootdelay;
  240. #endif
  241. #ifdef CONFIG_PREBOOT
  242. char *p;
  243. #endif
  244. #ifdef CONFIG_BOOTCOUNT_LIMIT
  245. unsigned long bootcount = 0;
  246. unsigned long bootlimit = 0;
  247. char *bcs;
  248. char bcs_set[16];
  249. #endif /* CONFIG_BOOTCOUNT_LIMIT */
  250. #if defined(CONFIG_VFD) && defined(VFD_TEST_LOGO)
  251. ulong bmp = 0; /* default bitmap */
  252. extern int trab_vfd (ulong bitmap);
  253. #ifdef CONFIG_MODEM_SUPPORT
  254. if (do_mdm_init)
  255. bmp = 1; /* alternate bitmap */
  256. #endif
  257. trab_vfd (bmp);
  258. #endif /* CONFIG_VFD && VFD_TEST_LOGO */
  259. #if defined(CONFIG_UPDATE_TFTP)
  260. update_tftp ();
  261. #endif /* CONFIG_UPDATE_TFTP */
  262. #ifdef CONFIG_BOOTCOUNT_LIMIT
  263. bootcount = bootcount_load();
  264. bootcount++;
  265. bootcount_store (bootcount);
  266. sprintf (bcs_set, "%lu", bootcount);
  267. setenv ("bootcount", bcs_set);
  268. bcs = getenv ("bootlimit");
  269. bootlimit = bcs ? simple_strtoul (bcs, NULL, 10) : 0;
  270. #endif /* CONFIG_BOOTCOUNT_LIMIT */
  271. #ifdef CONFIG_MODEM_SUPPORT
  272. debug ("DEBUG: main_loop: do_mdm_init=%d\n", do_mdm_init);
  273. if (do_mdm_init) {
  274. char *str = strdup(getenv("mdm_cmd"));
  275. setenv ("preboot", str); /* set or delete definition */
  276. if (str != NULL)
  277. free (str);
  278. mdm_init(); /* wait for modem connection */
  279. }
  280. #endif /* CONFIG_MODEM_SUPPORT */
  281. #ifdef CONFIG_VERSION_VARIABLE
  282. {
  283. extern char version_string[];
  284. setenv ("ver", version_string); /* set version variable */
  285. }
  286. #endif /* CONFIG_VERSION_VARIABLE */
  287. #ifdef CONFIG_SYS_HUSH_PARSER
  288. u_boot_hush_start ();
  289. #endif
  290. #if defined(CONFIG_HUSH_INIT_VAR)
  291. hush_init_var ();
  292. #endif
  293. #ifdef CONFIG_AUTO_COMPLETE
  294. install_auto_complete();
  295. #endif
  296. #ifdef CONFIG_PREBOOT
  297. if ((p = getenv ("preboot")) != NULL) {
  298. # ifdef CONFIG_AUTOBOOT_KEYED
  299. int prev = disable_ctrlc(1); /* disable Control C checking */
  300. # endif
  301. # ifndef CONFIG_SYS_HUSH_PARSER
  302. run_command (p, 0);
  303. # else
  304. parse_string_outer(p, FLAG_PARSE_SEMICOLON |
  305. FLAG_EXIT_FROM_LOOP);
  306. # endif
  307. # ifdef CONFIG_AUTOBOOT_KEYED
  308. disable_ctrlc(prev); /* restore Control C checking */
  309. # endif
  310. }
  311. #endif /* CONFIG_PREBOOT */
  312. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  313. s = getenv ("bootdelay");
  314. bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
  315. debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
  316. # ifdef CONFIG_BOOT_RETRY_TIME
  317. init_cmd_timeout ();
  318. # endif /* CONFIG_BOOT_RETRY_TIME */
  319. #ifdef CONFIG_POST
  320. if (gd->flags & GD_FLG_POSTFAIL) {
  321. s = getenv("failbootcmd");
  322. }
  323. else
  324. #endif /* CONFIG_POST */
  325. #ifdef CONFIG_BOOTCOUNT_LIMIT
  326. if (bootlimit && (bootcount > bootlimit)) {
  327. printf ("Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n",
  328. (unsigned)bootlimit);
  329. s = getenv ("altbootcmd");
  330. }
  331. else
  332. #endif /* CONFIG_BOOTCOUNT_LIMIT */
  333. s = getenv ("bootcmd");
  334. debug ("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");
  335. if (bootdelay >= 0 && s && !abortboot (bootdelay)) {
  336. # ifdef CONFIG_AUTOBOOT_KEYED
  337. int prev = disable_ctrlc(1); /* disable Control C checking */
  338. # endif
  339. # ifndef CONFIG_SYS_HUSH_PARSER
  340. run_command (s, 0);
  341. # else
  342. parse_string_outer(s, FLAG_PARSE_SEMICOLON |
  343. FLAG_EXIT_FROM_LOOP);
  344. # endif
  345. # ifdef CONFIG_AUTOBOOT_KEYED
  346. disable_ctrlc(prev); /* restore Control C checking */
  347. # endif
  348. }
  349. # ifdef CONFIG_MENUKEY
  350. if (menukey == CONFIG_MENUKEY) {
  351. s = getenv("menucmd");
  352. if (s) {
  353. # ifndef CONFIG_SYS_HUSH_PARSER
  354. run_command (s, 0);
  355. # else
  356. parse_string_outer(s, FLAG_PARSE_SEMICOLON |
  357. FLAG_EXIT_FROM_LOOP);
  358. # endif
  359. }
  360. }
  361. #endif /* CONFIG_MENUKEY */
  362. #endif /* CONFIG_BOOTDELAY */
  363. #ifdef CONFIG_AMIGAONEG3SE
  364. {
  365. extern void video_banner(void);
  366. video_banner();
  367. }
  368. #endif
  369. /*
  370. * Main Loop for Monitor Command Processing
  371. */
  372. #ifdef CONFIG_SYS_HUSH_PARSER
  373. parse_file_outer();
  374. /* This point is never reached */
  375. for (;;);
  376. #else
  377. for (;;) {
  378. #ifdef CONFIG_BOOT_RETRY_TIME
  379. if (rc >= 0) {
  380. /* Saw enough of a valid command to
  381. * restart the timeout.
  382. */
  383. reset_cmd_timeout();
  384. }
  385. #endif
  386. len = readline (CONFIG_SYS_PROMPT);
  387. flag = 0; /* assume no special flags for now */
  388. if (len > 0)
  389. strcpy (lastcommand, console_buffer);
  390. else if (len == 0)
  391. flag |= CMD_FLAG_REPEAT;
  392. #ifdef CONFIG_BOOT_RETRY_TIME
  393. else if (len == -2) {
  394. /* -2 means timed out, retry autoboot
  395. */
  396. puts ("\nTimed out waiting for command\n");
  397. # ifdef CONFIG_RESET_TO_RETRY
  398. /* Reinit board to run initialization code again */
  399. do_reset (NULL, 0, 0, NULL);
  400. # else
  401. return; /* retry autoboot */
  402. # endif
  403. }
  404. #endif
  405. if (len == -1)
  406. puts ("<INTERRUPT>\n");
  407. else
  408. rc = run_command (lastcommand, flag);
  409. if (rc <= 0) {
  410. /* invalid command or not repeatable, forget it */
  411. lastcommand[0] = 0;
  412. }
  413. }
  414. #endif /*CONFIG_SYS_HUSH_PARSER*/
  415. }
  416. #ifdef CONFIG_BOOT_RETRY_TIME
  417. /***************************************************************************
  418. * initialize command line timeout
  419. */
  420. void init_cmd_timeout(void)
  421. {
  422. char *s = getenv ("bootretry");
  423. if (s != NULL)
  424. retry_time = (int)simple_strtol(s, NULL, 10);
  425. else
  426. retry_time = CONFIG_BOOT_RETRY_TIME;
  427. if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
  428. retry_time = CONFIG_BOOT_RETRY_MIN;
  429. }
  430. /***************************************************************************
  431. * reset command line timeout to retry_time seconds
  432. */
  433. void reset_cmd_timeout(void)
  434. {
  435. endtime = endtick(retry_time);
  436. }
  437. #endif
  438. #ifdef CONFIG_CMDLINE_EDITING
  439. /*
  440. * cmdline-editing related codes from vivi.
  441. * Author: Janghoon Lyu <nandy@mizi.com>
  442. */
  443. #define putnstr(str,n) do { \
  444. printf ("%.*s", (int)n, str); \
  445. } while (0)
  446. #define CTL_CH(c) ((c) - 'a' + 1)
  447. #define MAX_CMDBUF_SIZE 256
  448. #define CTL_BACKSPACE ('\b')
  449. #define DEL ((char)255)
  450. #define DEL7 ((char)127)
  451. #define CREAD_HIST_CHAR ('!')
  452. #define getcmd_putch(ch) putc(ch)
  453. #define getcmd_getch() getc()
  454. #define getcmd_cbeep() getcmd_putch('\a')
  455. #define HIST_MAX 20
  456. #define HIST_SIZE MAX_CMDBUF_SIZE
  457. static int hist_max = 0;
  458. static int hist_add_idx = 0;
  459. static int hist_cur = -1;
  460. unsigned hist_num = 0;
  461. char* hist_list[HIST_MAX];
  462. char hist_lines[HIST_MAX][HIST_SIZE];
  463. #define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
  464. static void hist_init(void)
  465. {
  466. int i;
  467. hist_max = 0;
  468. hist_add_idx = 0;
  469. hist_cur = -1;
  470. hist_num = 0;
  471. for (i = 0; i < HIST_MAX; i++) {
  472. hist_list[i] = hist_lines[i];
  473. hist_list[i][0] = '\0';
  474. }
  475. }
  476. static void cread_add_to_hist(char *line)
  477. {
  478. strcpy(hist_list[hist_add_idx], line);
  479. if (++hist_add_idx >= HIST_MAX)
  480. hist_add_idx = 0;
  481. if (hist_add_idx > hist_max)
  482. hist_max = hist_add_idx;
  483. hist_num++;
  484. }
  485. static char* hist_prev(void)
  486. {
  487. char *ret;
  488. int old_cur;
  489. if (hist_cur < 0)
  490. return NULL;
  491. old_cur = hist_cur;
  492. if (--hist_cur < 0)
  493. hist_cur = hist_max;
  494. if (hist_cur == hist_add_idx) {
  495. hist_cur = old_cur;
  496. ret = NULL;
  497. } else
  498. ret = hist_list[hist_cur];
  499. return (ret);
  500. }
  501. static char* hist_next(void)
  502. {
  503. char *ret;
  504. if (hist_cur < 0)
  505. return NULL;
  506. if (hist_cur == hist_add_idx)
  507. return NULL;
  508. if (++hist_cur > hist_max)
  509. hist_cur = 0;
  510. if (hist_cur == hist_add_idx) {
  511. ret = "";
  512. } else
  513. ret = hist_list[hist_cur];
  514. return (ret);
  515. }
  516. #ifndef CONFIG_CMDLINE_EDITING
  517. static void cread_print_hist_list(void)
  518. {
  519. int i;
  520. unsigned long n;
  521. n = hist_num - hist_max;
  522. i = hist_add_idx + 1;
  523. while (1) {
  524. if (i > hist_max)
  525. i = 0;
  526. if (i == hist_add_idx)
  527. break;
  528. printf("%s\n", hist_list[i]);
  529. n++;
  530. i++;
  531. }
  532. }
  533. #endif /* CONFIG_CMDLINE_EDITING */
  534. #define BEGINNING_OF_LINE() { \
  535. while (num) { \
  536. getcmd_putch(CTL_BACKSPACE); \
  537. num--; \
  538. } \
  539. }
  540. #define ERASE_TO_EOL() { \
  541. if (num < eol_num) { \
  542. int tmp; \
  543. for (tmp = num; tmp < eol_num; tmp++) \
  544. getcmd_putch(' '); \
  545. while (tmp-- > num) \
  546. getcmd_putch(CTL_BACKSPACE); \
  547. eol_num = num; \
  548. } \
  549. }
  550. #define REFRESH_TO_EOL() { \
  551. if (num < eol_num) { \
  552. wlen = eol_num - num; \
  553. putnstr(buf + num, wlen); \
  554. num = eol_num; \
  555. } \
  556. }
  557. static void cread_add_char(char ichar, int insert, unsigned long *num,
  558. unsigned long *eol_num, char *buf, unsigned long len)
  559. {
  560. unsigned long wlen;
  561. /* room ??? */
  562. if (insert || *num == *eol_num) {
  563. if (*eol_num > len - 1) {
  564. getcmd_cbeep();
  565. return;
  566. }
  567. (*eol_num)++;
  568. }
  569. if (insert) {
  570. wlen = *eol_num - *num;
  571. if (wlen > 1) {
  572. memmove(&buf[*num+1], &buf[*num], wlen-1);
  573. }
  574. buf[*num] = ichar;
  575. putnstr(buf + *num, wlen);
  576. (*num)++;
  577. while (--wlen) {
  578. getcmd_putch(CTL_BACKSPACE);
  579. }
  580. } else {
  581. /* echo the character */
  582. wlen = 1;
  583. buf[*num] = ichar;
  584. putnstr(buf + *num, wlen);
  585. (*num)++;
  586. }
  587. }
  588. static void cread_add_str(char *str, int strsize, int insert, unsigned long *num,
  589. unsigned long *eol_num, char *buf, unsigned long len)
  590. {
  591. while (strsize--) {
  592. cread_add_char(*str, insert, num, eol_num, buf, len);
  593. str++;
  594. }
  595. }
  596. static int cread_line(const char *const prompt, char *buf, unsigned int *len)
  597. {
  598. unsigned long num = 0;
  599. unsigned long eol_num = 0;
  600. unsigned long wlen;
  601. char ichar;
  602. int insert = 1;
  603. int esc_len = 0;
  604. char esc_save[8];
  605. int init_len = strlen(buf);
  606. if (init_len)
  607. cread_add_str(buf, init_len, 1, &num, &eol_num, buf, *len);
  608. while (1) {
  609. #ifdef CONFIG_BOOT_RETRY_TIME
  610. while (!tstc()) { /* while no incoming data */
  611. if (retry_time >= 0 && get_ticks() > endtime)
  612. return (-2); /* timed out */
  613. }
  614. #endif
  615. ichar = getcmd_getch();
  616. if ((ichar == '\n') || (ichar == '\r')) {
  617. putc('\n');
  618. break;
  619. }
  620. /*
  621. * handle standard linux xterm esc sequences for arrow key, etc.
  622. */
  623. if (esc_len != 0) {
  624. if (esc_len == 1) {
  625. if (ichar == '[') {
  626. esc_save[esc_len] = ichar;
  627. esc_len = 2;
  628. } else {
  629. cread_add_str(esc_save, esc_len, insert,
  630. &num, &eol_num, buf, *len);
  631. esc_len = 0;
  632. }
  633. continue;
  634. }
  635. switch (ichar) {
  636. case 'D': /* <- key */
  637. ichar = CTL_CH('b');
  638. esc_len = 0;
  639. break;
  640. case 'C': /* -> key */
  641. ichar = CTL_CH('f');
  642. esc_len = 0;
  643. break; /* pass off to ^F handler */
  644. case 'H': /* Home key */
  645. ichar = CTL_CH('a');
  646. esc_len = 0;
  647. break; /* pass off to ^A handler */
  648. case 'A': /* up arrow */
  649. ichar = CTL_CH('p');
  650. esc_len = 0;
  651. break; /* pass off to ^P handler */
  652. case 'B': /* down arrow */
  653. ichar = CTL_CH('n');
  654. esc_len = 0;
  655. break; /* pass off to ^N handler */
  656. default:
  657. esc_save[esc_len++] = ichar;
  658. cread_add_str(esc_save, esc_len, insert,
  659. &num, &eol_num, buf, *len);
  660. esc_len = 0;
  661. continue;
  662. }
  663. }
  664. switch (ichar) {
  665. case 0x1b:
  666. if (esc_len == 0) {
  667. esc_save[esc_len] = ichar;
  668. esc_len = 1;
  669. } else {
  670. puts("impossible condition #876\n");
  671. esc_len = 0;
  672. }
  673. break;
  674. case CTL_CH('a'):
  675. BEGINNING_OF_LINE();
  676. break;
  677. case CTL_CH('c'): /* ^C - break */
  678. *buf = '\0'; /* discard input */
  679. return (-1);
  680. case CTL_CH('f'):
  681. if (num < eol_num) {
  682. getcmd_putch(buf[num]);
  683. num++;
  684. }
  685. break;
  686. case CTL_CH('b'):
  687. if (num) {
  688. getcmd_putch(CTL_BACKSPACE);
  689. num--;
  690. }
  691. break;
  692. case CTL_CH('d'):
  693. if (num < eol_num) {
  694. wlen = eol_num - num - 1;
  695. if (wlen) {
  696. memmove(&buf[num], &buf[num+1], wlen);
  697. putnstr(buf + num, wlen);
  698. }
  699. getcmd_putch(' ');
  700. do {
  701. getcmd_putch(CTL_BACKSPACE);
  702. } while (wlen--);
  703. eol_num--;
  704. }
  705. break;
  706. case CTL_CH('k'):
  707. ERASE_TO_EOL();
  708. break;
  709. case CTL_CH('e'):
  710. REFRESH_TO_EOL();
  711. break;
  712. case CTL_CH('o'):
  713. insert = !insert;
  714. break;
  715. case CTL_CH('x'):
  716. case CTL_CH('u'):
  717. BEGINNING_OF_LINE();
  718. ERASE_TO_EOL();
  719. break;
  720. case DEL:
  721. case DEL7:
  722. case 8:
  723. if (num) {
  724. wlen = eol_num - num;
  725. num--;
  726. memmove(&buf[num], &buf[num+1], wlen);
  727. getcmd_putch(CTL_BACKSPACE);
  728. putnstr(buf + num, wlen);
  729. getcmd_putch(' ');
  730. do {
  731. getcmd_putch(CTL_BACKSPACE);
  732. } while (wlen--);
  733. eol_num--;
  734. }
  735. break;
  736. case CTL_CH('p'):
  737. case CTL_CH('n'):
  738. {
  739. char * hline;
  740. esc_len = 0;
  741. if (ichar == CTL_CH('p'))
  742. hline = hist_prev();
  743. else
  744. hline = hist_next();
  745. if (!hline) {
  746. getcmd_cbeep();
  747. continue;
  748. }
  749. /* nuke the current line */
  750. /* first, go home */
  751. BEGINNING_OF_LINE();
  752. /* erase to end of line */
  753. ERASE_TO_EOL();
  754. /* copy new line into place and display */
  755. strcpy(buf, hline);
  756. eol_num = strlen(buf);
  757. REFRESH_TO_EOL();
  758. continue;
  759. }
  760. #ifdef CONFIG_AUTO_COMPLETE
  761. case '\t': {
  762. int num2, col;
  763. /* do not autocomplete when in the middle */
  764. if (num < eol_num) {
  765. getcmd_cbeep();
  766. break;
  767. }
  768. buf[num] = '\0';
  769. col = strlen(prompt) + eol_num;
  770. num2 = num;
  771. if (cmd_auto_complete(prompt, buf, &num2, &col)) {
  772. col = num2 - num;
  773. num += col;
  774. eol_num += col;
  775. }
  776. break;
  777. }
  778. #endif
  779. default:
  780. cread_add_char(ichar, insert, &num, &eol_num, buf, *len);
  781. break;
  782. }
  783. }
  784. *len = eol_num;
  785. buf[eol_num] = '\0'; /* lose the newline */
  786. if (buf[0] && buf[0] != CREAD_HIST_CHAR)
  787. cread_add_to_hist(buf);
  788. hist_cur = hist_add_idx;
  789. return 0;
  790. }
  791. #endif /* CONFIG_CMDLINE_EDITING */
  792. /****************************************************************************/
  793. /*
  794. * Prompt for input and read a line.
  795. * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0,
  796. * time out when time goes past endtime (timebase time in ticks).
  797. * Return: number of read characters
  798. * -1 if break
  799. * -2 if timed out
  800. */
  801. int readline (const char *const prompt)
  802. {
  803. /*
  804. * If console_buffer isn't 0-length the user will be prompted to modify
  805. * it instead of entering it from scratch as desired.
  806. */
  807. console_buffer[0] = '\0';
  808. return readline_into_buffer(prompt, console_buffer);
  809. }
  810. int readline_into_buffer (const char *const prompt, char * buffer)
  811. {
  812. char *p = buffer;
  813. #ifdef CONFIG_CMDLINE_EDITING
  814. unsigned int len=MAX_CMDBUF_SIZE;
  815. int rc;
  816. static int initted = 0;
  817. /*
  818. * History uses a global array which is not
  819. * writable until after relocation to RAM.
  820. * Revert to non-history version if still
  821. * running from flash.
  822. */
  823. if (gd->flags & GD_FLG_RELOC) {
  824. if (!initted) {
  825. hist_init();
  826. initted = 1;
  827. }
  828. if (prompt)
  829. puts (prompt);
  830. rc = cread_line(prompt, p, &len);
  831. return rc < 0 ? rc : len;
  832. } else {
  833. #endif /* CONFIG_CMDLINE_EDITING */
  834. char * p_buf = p;
  835. int n = 0; /* buffer index */
  836. int plen = 0; /* prompt length */
  837. int col; /* output column cnt */
  838. char c;
  839. /* print prompt */
  840. if (prompt) {
  841. plen = strlen (prompt);
  842. puts (prompt);
  843. }
  844. col = plen;
  845. for (;;) {
  846. #ifdef CONFIG_BOOT_RETRY_TIME
  847. while (!tstc()) { /* while no incoming data */
  848. if (retry_time >= 0 && get_ticks() > endtime)
  849. return (-2); /* timed out */
  850. }
  851. #endif
  852. WATCHDOG_RESET(); /* Trigger watchdog, if needed */
  853. #ifdef CONFIG_SHOW_ACTIVITY
  854. while (!tstc()) {
  855. extern void show_activity(int arg);
  856. show_activity(0);
  857. }
  858. #endif
  859. c = getc();
  860. /*
  861. * Special character handling
  862. */
  863. switch (c) {
  864. case '\r': /* Enter */
  865. case '\n':
  866. *p = '\0';
  867. puts ("\r\n");
  868. return (p - p_buf);
  869. case '\0': /* nul */
  870. continue;
  871. case 0x03: /* ^C - break */
  872. p_buf[0] = '\0'; /* discard input */
  873. return (-1);
  874. case 0x15: /* ^U - erase line */
  875. while (col > plen) {
  876. puts (erase_seq);
  877. --col;
  878. }
  879. p = p_buf;
  880. n = 0;
  881. continue;
  882. case 0x17: /* ^W - erase word */
  883. p=delete_char(p_buf, p, &col, &n, plen);
  884. while ((n > 0) && (*p != ' ')) {
  885. p=delete_char(p_buf, p, &col, &n, plen);
  886. }
  887. continue;
  888. case 0x08: /* ^H - backspace */
  889. case 0x7F: /* DEL - backspace */
  890. p=delete_char(p_buf, p, &col, &n, plen);
  891. continue;
  892. default:
  893. /*
  894. * Must be a normal character then
  895. */
  896. if (n < CONFIG_SYS_CBSIZE-2) {
  897. if (c == '\t') { /* expand TABs */
  898. #ifdef CONFIG_AUTO_COMPLETE
  899. /* if auto completion triggered just continue */
  900. *p = '\0';
  901. if (cmd_auto_complete(prompt, console_buffer, &n, &col)) {
  902. p = p_buf + n; /* reset */
  903. continue;
  904. }
  905. #endif
  906. puts (tab_seq+(col&07));
  907. col += 8 - (col&07);
  908. } else {
  909. ++col; /* echo input */
  910. putc (c);
  911. }
  912. *p++ = c;
  913. ++n;
  914. } else { /* Buffer full */
  915. putc ('\a');
  916. }
  917. }
  918. }
  919. #ifdef CONFIG_CMDLINE_EDITING
  920. }
  921. #endif
  922. }
  923. /****************************************************************************/
  924. static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen)
  925. {
  926. char *s;
  927. if (*np == 0) {
  928. return (p);
  929. }
  930. if (*(--p) == '\t') { /* will retype the whole line */
  931. while (*colp > plen) {
  932. puts (erase_seq);
  933. (*colp)--;
  934. }
  935. for (s=buffer; s<p; ++s) {
  936. if (*s == '\t') {
  937. puts (tab_seq+((*colp) & 07));
  938. *colp += 8 - ((*colp) & 07);
  939. } else {
  940. ++(*colp);
  941. putc (*s);
  942. }
  943. }
  944. } else {
  945. puts (erase_seq);
  946. (*colp)--;
  947. }
  948. (*np)--;
  949. return (p);
  950. }
  951. /****************************************************************************/
  952. int parse_line (char *line, char *argv[])
  953. {
  954. int nargs = 0;
  955. #ifdef DEBUG_PARSER
  956. printf ("parse_line: \"%s\"\n", line);
  957. #endif
  958. while (nargs < CONFIG_SYS_MAXARGS) {
  959. /* skip any white space */
  960. while ((*line == ' ') || (*line == '\t')) {
  961. ++line;
  962. }
  963. if (*line == '\0') { /* end of line, no more args */
  964. argv[nargs] = NULL;
  965. #ifdef DEBUG_PARSER
  966. printf ("parse_line: nargs=%d\n", nargs);
  967. #endif
  968. return (nargs);
  969. }
  970. argv[nargs++] = line; /* begin of argument string */
  971. /* find end of string */
  972. while (*line && (*line != ' ') && (*line != '\t')) {
  973. ++line;
  974. }
  975. if (*line == '\0') { /* end of line, no more args */
  976. argv[nargs] = NULL;
  977. #ifdef DEBUG_PARSER
  978. printf ("parse_line: nargs=%d\n", nargs);
  979. #endif
  980. return (nargs);
  981. }
  982. *line++ = '\0'; /* terminate current arg */
  983. }
  984. printf ("** Too many args (max. %d) **\n", CONFIG_SYS_MAXARGS);
  985. #ifdef DEBUG_PARSER
  986. printf ("parse_line: nargs=%d\n", nargs);
  987. #endif
  988. return (nargs);
  989. }
  990. /****************************************************************************/
  991. static void process_macros (const char *input, char *output)
  992. {
  993. char c, prev;
  994. const char *varname_start = NULL;
  995. int inputcnt = strlen (input);
  996. int outputcnt = CONFIG_SYS_CBSIZE;
  997. int state = 0; /* 0 = waiting for '$' */
  998. /* 1 = waiting for '(' or '{' */
  999. /* 2 = waiting for ')' or '}' */
  1000. /* 3 = waiting for ''' */
  1001. #ifdef DEBUG_PARSER
  1002. char *output_start = output;
  1003. printf ("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", strlen (input),
  1004. input);
  1005. #endif
  1006. prev = '\0'; /* previous character */
  1007. while (inputcnt && outputcnt) {
  1008. c = *input++;
  1009. inputcnt--;
  1010. if (state != 3) {
  1011. /* remove one level of escape characters */
  1012. if ((c == '\\') && (prev != '\\')) {
  1013. if (inputcnt-- == 0)
  1014. break;
  1015. prev = c;
  1016. c = *input++;
  1017. }
  1018. }
  1019. switch (state) {
  1020. case 0: /* Waiting for (unescaped) $ */
  1021. if ((c == '\'') && (prev != '\\')) {
  1022. state = 3;
  1023. break;
  1024. }
  1025. if ((c == '$') && (prev != '\\')) {
  1026. state++;
  1027. } else {
  1028. *(output++) = c;
  1029. outputcnt--;
  1030. }
  1031. break;
  1032. case 1: /* Waiting for ( */
  1033. if (c == '(' || c == '{') {
  1034. state++;
  1035. varname_start = input;
  1036. } else {
  1037. state = 0;
  1038. *(output++) = '$';
  1039. outputcnt--;
  1040. if (outputcnt) {
  1041. *(output++) = c;
  1042. outputcnt--;
  1043. }
  1044. }
  1045. break;
  1046. case 2: /* Waiting for ) */
  1047. if (c == ')' || c == '}') {
  1048. int i;
  1049. char envname[CONFIG_SYS_CBSIZE], *envval;
  1050. int envcnt = input - varname_start - 1; /* Varname # of chars */
  1051. /* Get the varname */
  1052. for (i = 0; i < envcnt; i++) {
  1053. envname[i] = varname_start[i];
  1054. }
  1055. envname[i] = 0;
  1056. /* Get its value */
  1057. envval = getenv (envname);
  1058. /* Copy into the line if it exists */
  1059. if (envval != NULL)
  1060. while ((*envval) && outputcnt) {
  1061. *(output++) = *(envval++);
  1062. outputcnt--;
  1063. }
  1064. /* Look for another '$' */
  1065. state = 0;
  1066. }
  1067. break;
  1068. case 3: /* Waiting for ' */
  1069. if ((c == '\'') && (prev != '\\')) {
  1070. state = 0;
  1071. } else {
  1072. *(output++) = c;
  1073. outputcnt--;
  1074. }
  1075. break;
  1076. }
  1077. prev = c;
  1078. }
  1079. if (outputcnt)
  1080. *output = 0;
  1081. else
  1082. *(output - 1) = 0;
  1083. #ifdef DEBUG_PARSER
  1084. printf ("[PROCESS_MACROS] OUTPUT len %d: \"%s\"\n",
  1085. strlen (output_start), output_start);
  1086. #endif
  1087. }
  1088. /****************************************************************************
  1089. * returns:
  1090. * 1 - command executed, repeatable
  1091. * 0 - command executed but not repeatable, interrupted commands are
  1092. * always considered not repeatable
  1093. * -1 - not executed (unrecognized, bootd recursion or too many args)
  1094. * (If cmd is NULL or "" or longer than CONFIG_SYS_CBSIZE-1 it is
  1095. * considered unrecognized)
  1096. *
  1097. * WARNING:
  1098. *
  1099. * We must create a temporary copy of the command since the command we get
  1100. * may be the result from getenv(), which returns a pointer directly to
  1101. * the environment data, which may change magicly when the command we run
  1102. * creates or modifies environment variables (like "bootp" does).
  1103. */
  1104. int run_command (const char *cmd, int flag)
  1105. {
  1106. cmd_tbl_t *cmdtp;
  1107. char cmdbuf[CONFIG_SYS_CBSIZE]; /* working copy of cmd */
  1108. char *token; /* start of token in cmdbuf */
  1109. char *sep; /* end of token (separator) in cmdbuf */
  1110. char finaltoken[CONFIG_SYS_CBSIZE];
  1111. char *str = cmdbuf;
  1112. char *argv[CONFIG_SYS_MAXARGS + 1]; /* NULL terminated */
  1113. int argc, inquotes;
  1114. int repeatable = 1;
  1115. int rc = 0;
  1116. #ifdef DEBUG_PARSER
  1117. printf ("[RUN_COMMAND] cmd[%p]=\"", cmd);
  1118. puts (cmd ? cmd : "NULL"); /* use puts - string may be loooong */
  1119. puts ("\"\n");
  1120. #endif
  1121. clear_ctrlc(); /* forget any previous Control C */
  1122. if (!cmd || !*cmd) {
  1123. return -1; /* empty command */
  1124. }
  1125. if (strlen(cmd) >= CONFIG_SYS_CBSIZE) {
  1126. puts ("## Command too long!\n");
  1127. return -1;
  1128. }
  1129. strcpy (cmdbuf, cmd);
  1130. /* Process separators and check for invalid
  1131. * repeatable commands
  1132. */
  1133. #ifdef DEBUG_PARSER
  1134. printf ("[PROCESS_SEPARATORS] %s\n", cmd);
  1135. #endif
  1136. while (*str) {
  1137. /*
  1138. * Find separator, or string end
  1139. * Allow simple escape of ';' by writing "\;"
  1140. */
  1141. for (inquotes = 0, sep = str; *sep; sep++) {
  1142. if ((*sep=='\'') &&
  1143. (*(sep-1) != '\\'))
  1144. inquotes=!inquotes;
  1145. if (!inquotes &&
  1146. (*sep == ';') && /* separator */
  1147. ( sep != str) && /* past string start */
  1148. (*(sep-1) != '\\')) /* and NOT escaped */
  1149. break;
  1150. }
  1151. /*
  1152. * Limit the token to data between separators
  1153. */
  1154. token = str;
  1155. if (*sep) {
  1156. str = sep + 1; /* start of command for next pass */
  1157. *sep = '\0';
  1158. }
  1159. else
  1160. str = sep; /* no more commands for next pass */
  1161. #ifdef DEBUG_PARSER
  1162. printf ("token: \"%s\"\n", token);
  1163. #endif
  1164. /* find macros in this token and replace them */
  1165. process_macros (token, finaltoken);
  1166. /* Extract arguments */
  1167. if ((argc = parse_line (finaltoken, argv)) == 0) {
  1168. rc = -1; /* no command at all */
  1169. continue;
  1170. }
  1171. /* Look up command in command table */
  1172. if ((cmdtp = find_cmd(argv[0])) == NULL) {
  1173. printf ("Unknown command '%s' - try 'help'\n", argv[0]);
  1174. rc = -1; /* give up after bad command */
  1175. continue;
  1176. }
  1177. /* found - check max args */
  1178. if (argc > cmdtp->maxargs) {
  1179. cmd_usage(cmdtp);
  1180. rc = -1;
  1181. continue;
  1182. }
  1183. #if defined(CONFIG_CMD_BOOTD)
  1184. /* avoid "bootd" recursion */
  1185. if (cmdtp->cmd == do_bootd) {
  1186. #ifdef DEBUG_PARSER
  1187. printf ("[%s]\n", finaltoken);
  1188. #endif
  1189. if (flag & CMD_FLAG_BOOTD) {
  1190. puts ("'bootd' recursion detected\n");
  1191. rc = -1;
  1192. continue;
  1193. } else {
  1194. flag |= CMD_FLAG_BOOTD;
  1195. }
  1196. }
  1197. #endif
  1198. /* OK - call function to do the command */
  1199. if ((cmdtp->cmd) (cmdtp, flag, argc, argv) != 0) {
  1200. rc = -1;
  1201. }
  1202. repeatable &= cmdtp->repeatable;
  1203. /* Did the user stop this? */
  1204. if (had_ctrlc ())
  1205. return -1; /* if stopped then not repeatable */
  1206. }
  1207. return rc ? rc : repeatable;
  1208. }
  1209. /****************************************************************************/
  1210. #if defined(CONFIG_CMD_RUN)
  1211. int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  1212. {
  1213. int i;
  1214. if (argc < 2) {
  1215. cmd_usage(cmdtp);
  1216. return 1;
  1217. }
  1218. for (i=1; i<argc; ++i) {
  1219. char *arg;
  1220. if ((arg = getenv (argv[i])) == NULL) {
  1221. printf ("## Error: \"%s\" not defined\n", argv[i]);
  1222. return 1;
  1223. }
  1224. #ifndef CONFIG_SYS_HUSH_PARSER
  1225. if (run_command (arg, flag) == -1)
  1226. return 1;
  1227. #else
  1228. if (parse_string_outer(arg,
  1229. FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
  1230. return 1;
  1231. #endif
  1232. }
  1233. return 0;
  1234. }
  1235. #endif