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