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