command.c 6.9 KB

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