command.c 7.3 KB

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