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