command.c 7.0 KB

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