command.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. /*
  24. * Command Processor Table
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <cmd_cache.h>
  29. #include <cmd_mem.h>
  30. #include <cmd_boot.h>
  31. #include <cmd_flash.h>
  32. #include <cmd_bootm.h>
  33. #include <cmd_net.h>
  34. #include <cmd_nvedit.h>
  35. #include <cmd_misc.h>
  36. #include <cmd_kgdb.h>
  37. #include <cmd_ide.h>
  38. #include <cmd_disk.h>
  39. #include <cmd_console.h>
  40. #include <cmd_reginfo.h>
  41. #include <cmd_pcmcia.h>
  42. #include <cmd_autoscript.h>
  43. #include <cmd_diag.h>
  44. #include <cmd_eeprom.h>
  45. #include <cmd_i2c.h>
  46. #include <cmd_immap.h>
  47. #include <cmd_rtc.h>
  48. #include <cmd_elf.h>
  49. #include <cmd_fdc.h> /* Floppy support */
  50. #include <cmd_usb.h> /* USB support */
  51. #include <cmd_scsi.h>
  52. #include <cmd_pci.h>
  53. #include <cmd_mii.h>
  54. #include <cmd_dcr.h> /* 4xx DCR register access */
  55. #include <cmd_doc.h>
  56. #include <cmd_jffs2.h>
  57. #include <cmd_fpga.h>
  58. #include <cmd_bsp.h> /* board special functions */
  59. #include <cmd_bedbug.h>
  60. #include <cmd_elf.h>
  61. #include <cmd_dtt.h>
  62. #include <cmd_vfd.h> /* load a bitmap to the VFDs on TRAB */
  63. /*
  64. * HELP command
  65. */
  66. #define CMD_TBL_HELP MK_CMD_TBL_ENTRY( \
  67. "help", 1, CFG_MAXARGS, 1, do_help, \
  68. "help - print online help\n", \
  69. "[command ...]\n" \
  70. " - show help information (for 'command')\n" \
  71. "'help' prints online help for the monitor commands.\n\n" \
  72. "Without arguments, it prints a short usage message for all commands.\n\n" \
  73. "To get detailed help information for specific commands you can type\n" \
  74. "'help' with one or more command names as arguments.\n" \
  75. ),
  76. #define CMD_TBL_QUES MK_CMD_TBL_ENTRY( \
  77. "?", 1, CFG_MAXARGS, 1, do_help, \
  78. "? - alias for 'help'\n", \
  79. NULL \
  80. ),
  81. #define CMD_TBL_VERS MK_CMD_TBL_ENTRY( \
  82. "version", 4, 1, 1, do_version, \
  83. "version - print monitor version\n", \
  84. NULL \
  85. ),
  86. #define CMD_TBL_ECHO MK_CMD_TBL_ENTRY( \
  87. "echo", 4, CFG_MAXARGS, 1, do_echo, \
  88. "echo - echo args to console\n", \
  89. "[args..]\n" \
  90. " - echo args to console; \\c suppresses newline\n" \
  91. ),
  92. int
  93. do_version (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  94. {
  95. extern char version_string[];
  96. printf ("\n%s\n", version_string);
  97. return 0;
  98. }
  99. int
  100. do_echo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  101. {
  102. int i, putnl = 1;
  103. for (i = 1; i < argc; i++) {
  104. char *p = argv[i], c;
  105. if (i > 1)
  106. putc(' ');
  107. while ((c = *p++) != '\0')
  108. if (c == '\\' && *p == 'c') {
  109. putnl = 0;
  110. p++;
  111. }
  112. else
  113. putc(c);
  114. }
  115. if (putnl)
  116. putc('\n');
  117. return 0;
  118. }
  119. /*
  120. * Use puts() instead of printf() to avoid printf buffer overflow
  121. * for long help messages
  122. */
  123. int
  124. do_help (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  125. {
  126. int i;
  127. int rcode = 0;
  128. if (argc == 1) { /* print short help (usage) */
  129. for (cmdtp=&cmd_tbl[0]; cmdtp->name; cmdtp++) {
  130. /* allow user abort */
  131. if (ctrlc())
  132. return 1;
  133. if (cmdtp->usage == NULL)
  134. continue;
  135. puts (cmdtp->usage);
  136. }
  137. return 0;
  138. }
  139. /*
  140. * command help (long version)
  141. */
  142. for (i=1; i<argc; ++i) {
  143. if ((cmdtp = find_cmd(argv[i])) != NULL) {
  144. #ifdef CFG_LONGHELP
  145. /* found - print (long) help info */
  146. puts (cmdtp->name);
  147. putc (' ');
  148. if (cmdtp->help) {
  149. puts (cmdtp->help);
  150. } else {
  151. puts ("- No help available.\n");
  152. rcode = 1;
  153. }
  154. putc ('\n');
  155. #else /* no long help available */
  156. if (cmdtp->usage)
  157. puts (cmdtp->usage);
  158. #endif /* CFG_LONGHELP */
  159. }
  160. else {
  161. printf ("Unknown command '%s' - try 'help'"
  162. " without arguments for list of all"
  163. " known commands\n\n",
  164. argv[i]
  165. );
  166. rcode = 1;
  167. }
  168. }
  169. return rcode;
  170. }
  171. /***************************************************************************
  172. * find command table entry for a command
  173. */
  174. cmd_tbl_t *find_cmd(const char *cmd)
  175. {
  176. cmd_tbl_t *cmdtp;
  177. /* Search command table - Use linear search - it's a small table */
  178. for (cmdtp = &cmd_tbl[0]; cmdtp->name; cmdtp++) {
  179. if (strncmp (cmd, cmdtp->name, cmdtp->lmin) == 0)
  180. return cmdtp;
  181. }
  182. return NULL; /* not found */
  183. }
  184. /*
  185. * The commands in this table are sorted alphabetically by the
  186. * command name and in descending order by the command name string
  187. * length. This is to prevent conflicts in command name parsing.
  188. * Please ensure that new commands are added according to that rule.
  189. * Please use $(TOPDIR)/doc/README.commands as a reference AND make
  190. * sure it gets updated.
  191. */
  192. cmd_tbl_t cmd_tbl[] = {
  193. CMD_TBL_ASKENV
  194. CMD_TBL_ASM
  195. CMD_TBL_AUTOSCRIPT
  196. CMD_TBL_BASE
  197. CMD_TBL_BDINFO
  198. CMD_TBL_BOOTELF
  199. CMD_TBL_BOOTM
  200. CMD_TBL_BOOTP
  201. CMD_TBL_BOOTVX
  202. CMD_TBL_BOOTD
  203. CMD_TBL_BREAK
  204. CMD_TBL_BRGINFO
  205. CMD_TBL_CARINFO
  206. CMD_TBL_JFFS2_CHPART
  207. CMD_TBL_CMP
  208. CMD_TBL_CONINFO
  209. CMD_TBL_CONTINUE
  210. CMD_TBL_CP
  211. CMD_TBL_CRC
  212. CMD_TBL_DATE
  213. CMD_TBL_DCACHE
  214. CMD_TBL_DHCP
  215. CMD_TBL_DIAG
  216. CMD_TBL_DISK
  217. CMD_TBL_DMAINFO
  218. CMD_TBL_DIS
  219. CMD_TBL_DOCBOOT
  220. CMD_TBL_DOC
  221. CMD_TBL_DTT
  222. CMD_TBL_ECHO
  223. CMD_TBL_EEPROM
  224. CMD_TBL_FCCINFO
  225. CMD_TBL_FLERASE
  226. CMD_TBL_FDC
  227. CMD_TBL_FLINFO
  228. CMD_TBL_FPGA
  229. CMD_TBL_JFFS2_FSINFO
  230. CMD_TBL_JFFS2_FSLOAD
  231. CMD_TBL_GETDCR
  232. CMD_TBL_GO
  233. CMD_TBL_HELP
  234. CMD_TBL_HWFLOW
  235. CMD_TBL_I2CINFO
  236. CMD_TBL_ICACHE
  237. #ifdef CONFIG_8260
  238. CMD_TBL_ICINFO
  239. #endif
  240. CMD_TBL_IMD
  241. CMD_TBL_IMM
  242. CMD_TBL_INM
  243. CMD_TBL_IMW
  244. CMD_TBL_ICRC
  245. CMD_TBL_IPROBE
  246. CMD_TBL_ILOOP
  247. CMD_TBL_ISDRAM
  248. CMD_TBL_IDE
  249. CMD_TBL_IMINFO
  250. CMD_TBL_IOPINFO
  251. CMD_TBL_IOPSET
  252. CMD_TBL_IRQINFO
  253. CMD_TBL_KGDB
  254. CMD_TBL_LOADB
  255. CMD_TBL_LOADS
  256. CMD_TBL_LOOP
  257. CMD_TBL_JFFS2_LS
  258. CMD_TBL_MCCINFO
  259. CMD_TBL_MD
  260. CMD_TBL_MEMCINFO
  261. CMD_TBL_MII
  262. CMD_TBL_MM
  263. CMD_TBL_MTEST
  264. CMD_TBL_MUXINFO
  265. CMD_TBL_MW
  266. CMD_TBL_NEXT
  267. CMD_TBL_NM
  268. CMD_TBL_PCI
  269. CMD_TBL_PRINTENV
  270. CMD_TBL_PROTECT
  271. CMD_TBL_RARPB
  272. CMD_TBL_RDUMP
  273. CMD_TBL_PINIT
  274. CMD_TBL_REGINFO
  275. CMD_TBL_RESET
  276. CMD_TBL_RUN
  277. CMD_TBL_SAVEENV
  278. CMD_TBL_SAVES
  279. CMD_TBL_SCCINFO
  280. CMD_TBL_SCSIBOOT
  281. CMD_TBL_SCSI
  282. CMD_TBL_SETDCR
  283. CMD_TBL_SETENV
  284. CMD_TBL_SIINFO
  285. CMD_TBL_SITINFO
  286. CMD_TBL_SIUINFO
  287. CMD_TBL_MISC /* sleep */
  288. CMD_TBL_SMCINFO
  289. CMD_TBL_SPIINFO
  290. CMD_TBL_STACK
  291. CMD_TBL_STEP
  292. CMD_TBL_TFTPB
  293. CMD_TBL_USBBOOT
  294. CMD_TBL_USB
  295. CMD_TBL_VERS
  296. CMD_TBL_BSP
  297. CMD_TBL_VFD
  298. CMD_TBL_QUES /* keep this ("help") the last entry */
  299. /* the following entry terminates this table */
  300. MK_CMD_TBL_ENTRY( NULL, 0, 0, 0, NULL, NULL, NULL )
  301. };