1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Program Loader commands File: ui_loadcmds.c
6 * User interface for program loader
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
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"
55 #include "cfe_device.h"
56 #include "cfe_console.h"
57 #include "cfe_devfuncs.h"
59 #include "ui_command.h"
63 #include "net_ether.h"
66 #include "cfe_fileops.h"
69 #include "bsp_config.h"
70 #include "cfe_loader.h"
71 #include "cfe_autoboot.h"
76 int ui_init_loadcmds(void);
77 static int ui_cmd_load(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
80 static int ui_cmd_save(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
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
)
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.
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
);
116 int ui_init_loadcmds(void)
123 "Save a region of memory to a remote file via TFTP",
124 "save [-options] host:filename startaddr length\n\n",
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|"
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|"
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)");
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|"
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|"
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");
183 "Start a previously loaded program.",
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");
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|"
199 "-tftp;Load the file using the TFTP protocol|"
200 "-fatfs;Load the file from a FAT file system|"
201 "-rawfs;Load the file from an unformatted file system|"
202 "-fs=*;Specify CFE file system name");
206 cmd_addcmd("autoboot",
209 "Automatic system bootstrap.",
211 "The 'autoboot' command causes an automatic system bootstrap from\n"
212 "a predefined list of devices and boot files. This list is \n"
213 "specific to the board and port of CFE. To try autobooting from\n"
214 "a specific device, you can specify the CFE device name on the command line.",
215 "-forever;Loop over devices until boot is successful|"
216 "-interruptible;Scan console between devices, drop to prompt if key pressed");
217 #endif /* CFG_AUTOBOOT */
224 static int ui_cmd_autoboot(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
230 if (cmd_sw_isset(cmd
,"-forever")) flags
|= CFE_AUTOFLG_TRYFOREVER
;
231 if (cmd_sw_isset(cmd
,"-interruptible")) flags
|= CFE_AUTOFLG_POLLCONSOLE
;
233 x
= cmd_getarg(cmd
,0);
234 res
= cfe_autoboot(x
,flags
);
238 #endif /* CFG_AUTOBOOT */
240 static int ui_cmd_go(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
244 arg
= cmd_getarg(cmd
,0);
246 cfe_loadargs
.la_entrypt
= getaddr(arg
);
249 if (cmd_sw_isset(cmd
,"-noclose")) {
250 cfe_loadargs
.la_flags
|= LOADFLG_NOCLOSE
;
253 cfe_go(&cfe_loadargs
);
260 static int ui_cmd_bootcommon(ui_cmdline_t
*cmd
,int argc
,char *argv
[],int flags
)
264 cfe_loadargs_t
*la
= &cfe_loadargs
;
267 la
->la_flags
= flags
;
269 arg
= cmd_getarg(cmd
,0);
270 strncpy(copy
,arg
,sizeof(copy
));
273 xprintf("No program name specified\n");
277 res
= ui_process_url(arg
,cmd
,la
);
278 if (res
< 0) return res
;
281 * Pick up the remaining command line parameters for use as
282 * arguments to the loaded program.
285 la
->la_options
= cmd_getarg(cmd
,1);
288 * Note: we might not come back here if we really launch the program.
291 xprintf("Loader:%s Filesys:%s Dev:%s File:%s Options:%s\n",
292 la
->la_loader
,la
->la_filesys
,la
->la_device
,la
->la_filename
,la
->la_options
);
294 res
= cfe_boot(la
->la_loader
,la
);
300 if (res
< 0) xprintf("Could not load %s: %s\n",copy
,cfe_errortext(res
));
306 static int ui_cmd_load(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
308 int flags
= LOADFLG_NOISY
;
310 return ui_cmd_bootcommon(cmd
,argc
,argv
,flags
);
316 static int ui_cmd_boot(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
318 int flags
= LOADFLG_NOISY
| LOADFLG_EXECUTE
;
320 return ui_cmd_bootcommon(cmd
,argc
,argv
,flags
);
323 static int ui_cmd_batch(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
325 int flags
= LOADFLG_NOISY
| LOADFLG_EXECUTE
| LOADFLG_BATCH
;
327 return ui_cmd_bootcommon(cmd
,argc
,argv
,flags
);
331 static int ui_cmd_save(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
339 fname
= cmd_getarg(cmd
,0);
341 if ((x
= cmd_getarg(cmd
,1))) {
342 start
= (uint8_t *) getaddr(x
);
345 return ui_showusage(cmd
);
348 if ((x
= cmd_getarg(cmd
,2))) {
352 return ui_showusage(cmd
);
357 res
= cfe_savedata("tftp","",fname
,start
,end
);
360 return ui_showerror(res
,"Could not dump data to network");
363 xprintf("%d bytes written to %s\n",res
,fname
);