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