1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * OS bootstrap File: cfe_boot.c
6 * This module handles OS bootstrap stuff
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"
58 #include "cfe_timer.h"
60 #include "cfe_error.h"
66 #include "net_ether.h"
69 #include "cfe_fileops.h"
70 #include "cfe_bootblock.h"
71 #include "bsp_config.h"
74 #include "cfe_loader.h"
77 extern int ui_docommands(char *buf
);
80 /* *********************************************************************
82 ********************************************************************* */
84 const char *bootvar_device
= "BOOT_DEVICE";
85 const char *bootvar_file
= "BOOT_FILE";
86 const char *bootvar_flags
= "BOOT_FLAGS";
88 cfe_loadargs_t cfe_loadargs
;
90 /* *********************************************************************
91 * splitpath(path,devname,filename)
93 * Split a path name (a boot path, in the form device:filename)
97 * path - pointer to path string
98 * devname - receives pointer to device name
99 * filename - receives pointer to file name
103 ********************************************************************* */
105 void splitpath(char *path
,char **devname
,char **filename
)
112 x
= strchr(path
,':');
115 *devname
= NULL
; /* path consists of device name */
119 *x
++ = '\0'; /* have both device and file name */
126 /* *********************************************************************
129 * Starts a previously loaded program. cfe_loadargs.la_entrypt
130 * must be set to the entry point of the program to be started
137 ********************************************************************* */
139 void cfe_go(cfe_loadargs_t
*la
)
141 if (la
->la_entrypt
== 0) {
142 xprintf("No program has been loaded.\n");
147 if (!(la
->la_flags
& LOADFLG_NOCLOSE
)) {
148 if (net_getparam(NET_DEVNAME
)) {
149 xprintf("Closing network.\n");
155 xprintf("Starting program at 0x%p\n",la
->la_entrypt
);
157 cfe_start(la
->la_entrypt
);
161 /* *********************************************************************
164 * Bootstrap the system.
167 * la - loader arguments
170 * error, or does not return
171 ********************************************************************* */
172 int cfe_boot(char *ldrname
,cfe_loadargs_t
*la
)
178 if (la
->la_flags
& LOADFLG_NOISY
) {
179 xprintf("Loading: ");
182 res
= cfe_load_program(ldrname
,la
);
185 if (la
->la_flags
& LOADFLG_NOISY
) {
186 xprintf("Failed.\n");
192 * Special case: If loading a batch file, just do the commands here
193 * and return. For batch files we don't want to set up the
194 * environment variables.
197 if (la
->la_flags
& LOADFLG_BATCH
) {
199 ui_docommands((char *) la
->la_entrypt
);
205 * Otherwise set up for running a real program.
208 if (la
->la_flags
& LOADFLG_NOISY
) {
209 xprintf("Entry at 0x%p\n",la
->la_entrypt
);
213 * Set up the environment variables for the bootstrap
217 env_setenv(bootvar_device
,la
->la_device
,ENV_FLG_BUILTIN
);
220 env_delenv(bootvar_device
);
223 if (la
->la_filename
) {
224 env_setenv(bootvar_file
,la
->la_filename
,ENV_FLG_BUILTIN
);
227 env_delenv(bootvar_file
);
230 if (la
->la_options
) {
231 env_setenv(bootvar_flags
,la
->la_options
,ENV_FLG_BUILTIN
);
234 env_delenv(bootvar_flags
);
238 * Banzai! Run the program.
241 if ((la
->la_flags
& LOADFLG_EXECUTE
) &&
242 (la
->la_entrypt
!= 0)) {