command.c 7.4 KB

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