GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / ui / ui_loadcmds.c
blobe9e3d114d7ca0e8f632b473d0950bbccf2f01fb9
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Program Loader commands File: ui_loadcmds.c
5 *
6 * User interface for program loader
7 *
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
9 *
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
48 #include "lib_types.h"
49 #include "lib_string.h"
50 #include "lib_queue.h"
51 #include "lib_malloc.h"
52 #include "lib_printf.h"
54 #include "cfe_iocb.h"
55 #include "cfe_device.h"
56 #include "cfe_console.h"
57 #include "cfe_devfuncs.h"
59 #include "ui_command.h"
60 #include "cfe.h"
62 #include "net_ebuf.h"
63 #include "net_ether.h"
64 #include "net_api.h"
66 #include "cfe_fileops.h"
67 #include "cfe_boot.h"
69 #include "bsp_config.h"
70 #include "cfe_loader.h"
71 #include "cfe_autoboot.h"
73 #include "url.h"
76 int ui_init_loadcmds(void);
77 static int ui_cmd_load(ui_cmdline_t *cmd,int argc,char *argv[]);
79 #if CFG_NETWORK
80 static int ui_cmd_save(ui_cmdline_t *cmd,int argc,char *argv[]);
81 #endif
83 #if CFG_AUTOBOOT
84 static int ui_cmd_autoboot(ui_cmdline_t *cmd,int argc,char *argv[]);
85 #endif /* CFG_AUTOBOOT */
86 static int ui_cmd_boot(ui_cmdline_t *cmd,int argc,char *argv[]);
87 static int ui_cmd_batch(ui_cmdline_t *cmd,int argc,char *argv[]);
88 static int ui_cmd_go(ui_cmdline_t *cmd,int argc,char *argv[]);
91 extern cfe_loadargs_t cfe_loadargs;
93 static long getaddr(char *str)
95 /*
96 * hold on to your lunch, this is really, really bad!
97 * Make 64-bit addresses expressed as 8-digit numbers
98 * sign extend automagically. Saves typing, but is very
99 * gross. Not very portable, either.
101 int longaddr = 0;
102 long newaddr;
104 longaddr = strlen(str);
105 if (memcmp(str,"0x",2) == 0) longaddr -= 2;
106 longaddr = (longaddr > 8) ? 1 : 0;
108 if (longaddr) newaddr = (long) xtoq(str);
109 else newaddr = (long) xtoi(str);
111 return newaddr;
116 int ui_init_loadcmds(void)
119 #if CFG_NETWORK
120 cmd_addcmd("save",
121 ui_cmd_save,
122 NULL,
123 "Save a region of memory to a remote file via TFTP",
124 "save [-options] host:filename startaddr length\n\n",
125 "");
126 #endif
128 cmd_addcmd("load",
129 ui_cmd_load,
130 NULL,
131 "Load an executable file into memory without executing it",
132 "load [-options] host:filename|dev:filename\n\n"
133 "This command loads an executable file into memory, but does not\n"
134 "execute it. It can be used for loading data files, overlays or\n"
135 "other programs needed before the 'boot' command is used. By\n"
136 "default, 'load' will load a raw binary at virtual address 0x20000000.",
137 "-elf;Load the file as an ELF executable|"
138 "-srec;Load the file as ASCII S-records|"
139 "-raw;Load the file as a raw binary|"
140 #if CFG_ZLIB || CFG_LZMA
141 "-z;Load compessed file|"
142 #endif
143 "-loader=*;Specify CFE loader name|"
144 "-tftp;Load the file using the TFTP protocol|"
145 "-fatfs;Load the file from a FAT file system|"
146 "-rawfs;Load the file from an unformatted file system|"
147 #if CFG_TCP && CFG_HTTPFS
148 "-http;Load the file using the HTTP protocol|"
149 #endif
150 "-fs=*;Specify CFE file system name|"
151 "-max=*;Specify the maximum number of bytes to load (raw only)|"
152 "-addr=*;Specify the load address (hex) (raw only)");
154 cmd_addcmd("boot",
155 ui_cmd_boot,
156 NULL,
157 "Load an executable file into memory and execute it",
158 "boot [-options] host:filename|dev:filename\n\n"
159 "This command loads and executes a program from a boot device\n"
160 "By default, 'boot' will load a raw binary at virtual \n"
161 "address 0x20000000 and then jump to that address",
162 "-elf;Load the file as an ELF executable|"
163 "-srec;Load the file as ASCII S-records|"
164 "-raw;Load the file as a raw binary|"
165 #if CFG_ZLIB || CFG_LZMA
166 "-z;Load compessed file|"
167 #endif
168 "-loader=*;Specify CFE loader name|"
169 "-tftp;Load the file using the TFTP protocol|"
170 "-fatfs;Load the file from a FAT file system|"
171 "-rawfs;Load the file from an unformatted file system|"
172 #if CFG_TCP && CFG_HTTPFS
173 "-http;Load the file using the HTTP protocol|"
174 #endif
175 "-fs=*;Specify CFE file system name|"
176 "-max=*;Specify the maximum number of bytes to load (raw only)|"
177 "-addr=*;Specify the load address (hex) (raw only)|"
178 "-noclose;Don't close network link before executing program");
180 cmd_addcmd("go",
181 ui_cmd_go,
182 NULL,
183 "Start a previously loaded program.",
184 "go [address]\n\n"
185 "The 'go' command will start a program previously loaded with \n"
186 "the 'load' command. You can override the start address by"
187 "specifying it as a parameter to the 'go' command.",
188 "-noclose;Don't close network link before executing program");
190 cmd_addcmd("batch",
191 ui_cmd_batch,
192 NULL,
193 "Load a batch file into memory and execute it",
194 "batch [-options] host:filename|dev:filename\n\n"
195 "This command loads and executes a batch file from a boot device",
196 #if CFG_ZLIB || CFG_LZMA
197 "-z;Load compessed file|"
198 #endif
199 #if CFG_ROMBOOT
200 "-raw;Load the file as a raw binary|"
201 "-max=*;Specify the maximum number of bytes to load (raw only)|"
202 "-addr=*;Specify the load address (hex) (raw only)|"
203 #endif
204 "-tftp;Load the file using the TFTP protocol|"
205 "-fatfs;Load the file from a FAT file system|"
206 "-rawfs;Load the file from an unformatted file system|"
207 "-fs=*;Specify CFE file system name");
209 #if CFG_AUTOBOOT
210 cmd_addcmd("autoboot",
211 ui_cmd_autoboot,
212 NULL,
213 "Automatic system bootstrap.",
214 "autoboot [dev]\n\n"
215 "The 'autoboot' command causes an automatic system bootstrap from\n"
216 "a predefined list of devices and boot files. This list is \n"
217 "specific to the board and port of CFE. To try autobooting from\n"
218 "a specific device, you can specify the CFE device name on the command line.",
219 "-forever;Loop over devices until boot is successful|"
220 "-interruptible;Scan console between devices, drop to prompt if key pressed");
221 #endif /* CFG_AUTOBOOT */
223 return 0;
227 #if CFG_AUTOBOOT
228 static int ui_cmd_autoboot(ui_cmdline_t *cmd,int argc,char *argv[])
230 int res;
231 char *x;
232 int flags = 0;
234 if (cmd_sw_isset(cmd,"-forever")) flags |= CFE_AUTOFLG_TRYFOREVER;
235 if (cmd_sw_isset(cmd,"-interruptible")) flags |= CFE_AUTOFLG_POLLCONSOLE;
237 x = cmd_getarg(cmd,0);
238 res = cfe_autoboot(x,flags);
240 return res;
242 #endif /* CFG_AUTOBOOT */
244 static int ui_cmd_go(ui_cmdline_t *cmd,int argc,char *argv[])
246 char *arg;
248 arg = cmd_getarg(cmd,0);
249 if (arg) {
250 cfe_loadargs.la_entrypt = getaddr(arg);
253 if (cmd_sw_isset(cmd,"-noclose")) {
254 cfe_loadargs.la_flags |= LOADFLG_NOCLOSE;
257 cfe_go(&cfe_loadargs);
259 return 0;
264 static int ui_cmd_bootcommon(ui_cmdline_t *cmd,int argc,char *argv[],int flags)
266 int res;
267 char *arg;
268 cfe_loadargs_t *la = &cfe_loadargs;
269 char copy[200];
271 la->la_flags = flags;
273 arg = cmd_getarg(cmd,0);
274 strncpy(copy,arg,sizeof(copy));
276 if (!arg) {
277 xprintf("No program name specified\n");
278 return -1;
281 res = ui_process_url(arg,cmd,la);
282 if (res < 0) return res;
285 * Pick up the remaining command line parameters for use as
286 * arguments to the loaded program.
289 la->la_options = cmd_getarg(cmd,1);
292 * Note: we might not come back here if we really launch the program.
295 xprintf("Loader:%s Filesys:%s Dev:%s File:%s Options:%s\n",
296 la->la_loader,la->la_filesys,la->la_device,la->la_filename,la->la_options);
298 res = cfe_boot(la->la_loader,la);
301 * Give the bad news.
304 if (res < 0) xprintf("Could not load %s: %s\n",copy,cfe_errortext(res));
306 return res;
310 static int ui_cmd_load(ui_cmdline_t *cmd,int argc,char *argv[])
312 int flags = LOADFLG_NOISY;
314 return ui_cmd_bootcommon(cmd,argc,argv,flags);
320 static int ui_cmd_boot(ui_cmdline_t *cmd,int argc,char *argv[])
322 int flags = LOADFLG_NOISY | LOADFLG_EXECUTE;
324 return ui_cmd_bootcommon(cmd,argc,argv,flags);
327 static int ui_cmd_batch(ui_cmdline_t *cmd,int argc,char *argv[])
329 int flags = LOADFLG_NOISY | LOADFLG_EXECUTE | LOADFLG_BATCH;
331 return ui_cmd_bootcommon(cmd,argc,argv,flags);
334 #if CFG_NETWORK
335 static int ui_cmd_save(ui_cmdline_t *cmd,int argc,char *argv[])
337 char *x;
338 uint8_t *start,*end;
339 int len;
340 char *fname;
341 int res;
343 fname = cmd_getarg(cmd,0);
345 if ((x = cmd_getarg(cmd,1))) {
346 start = (uint8_t *) getaddr(x);
348 else {
349 return ui_showusage(cmd);
352 if ((x = cmd_getarg(cmd,2))) {
353 len = xtoi(x);
355 else {
356 return ui_showusage(cmd);
359 end = start+len;
361 res = cfe_savedata("tftp","",fname,start,end);
363 if (res < 0) {
364 return ui_showerror(res,"Could not dump data to network");
366 else {
367 xprintf("%d bytes written to %s\n",res,fname);
370 return 0;
372 #endif