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