GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / main / cfe_boot.c
blobe6ad6276ac8ca0bdcd04cb57903c0514735249f2
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * OS bootstrap File: cfe_boot.c
5 *
6 * This module handles OS bootstrap stuff
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"
58 #include "cfe_timer.h"
60 #include "cfe_error.h"
62 #include "env_subr.h"
63 #include "cfe.h"
65 #include "net_ebuf.h"
66 #include "net_ether.h"
68 #include "net_api.h"
69 #include "cfe_fileops.h"
70 #include "cfe_bootblock.h"
71 #include "bsp_config.h"
72 #include "cfe_boot.h"
74 #include "cfe_loader.h"
76 #if CFG_UI
77 extern int ui_docommands(char *buf);
78 #endif
80 /* *********************************************************************
81 * data
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)
94 * into its parts
96 * Input parameters:
97 * path - pointer to path string
98 * devname - receives pointer to device name
99 * filename - receives pointer to file name
101 * Return value:
102 * nothing
103 ********************************************************************* */
105 void splitpath(char *path,char **devname,char **filename)
107 char *x;
109 *devname = NULL;
110 *filename = NULL;
112 x = strchr(path,':');
114 if (!x) {
115 *devname = NULL; /* path consists of device name */
116 *filename = path;
118 else {
119 *x++ = '\0'; /* have both device and file name */
120 *filename = x;
121 *devname = path;
126 /* *********************************************************************
127 * cfe_go(la)
129 * Starts a previously loaded program. cfe_loadargs.la_entrypt
130 * must be set to the entry point of the program to be started
132 * Input parameters:
133 * la - loader args
135 * Return value:
136 * does not return
137 ********************************************************************* */
139 void cfe_go(cfe_loadargs_t *la)
141 if (la->la_entrypt == 0) {
142 xprintf("No program has been loaded.\n");
143 return;
146 #if CFG_NETWORK
147 if (!(la->la_flags & LOADFLG_NOCLOSE)) {
148 if (net_getparam(NET_DEVNAME)) {
149 xprintf("Closing network.\n");
150 net_uninit();
153 #endif
155 xprintf("Starting program at 0x%p\n",la->la_entrypt);
157 cfe_start(la->la_entrypt);
161 /* *********************************************************************
162 * cfe_boot(la)
164 * Bootstrap the system.
166 * Input parameters:
167 * la - loader arguments
169 * Return value:
170 * error, or does not return
171 ********************************************************************* */
172 int cfe_boot(char *ldrname,cfe_loadargs_t *la)
174 int res;
176 la->la_entrypt = 0;
178 if (la->la_flags & LOADFLG_NOISY) {
179 xprintf("Loading: ");
182 res = cfe_load_program(ldrname,la);
184 if (res < 0) {
185 if (la->la_flags & LOADFLG_NOISY) {
186 xprintf("Failed.\n");
188 return res;
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) {
198 #if CFG_UI
199 ui_docommands((char *) la->la_entrypt);
200 #endif
201 return 0;
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
216 if (la->la_device) {
217 env_setenv(bootvar_device,la->la_device,ENV_FLG_BUILTIN);
219 else {
220 env_delenv(bootvar_device);
223 if (la->la_filename) {
224 env_setenv(bootvar_file,la->la_filename,ENV_FLG_BUILTIN);
226 else {
227 env_delenv(bootvar_file);
230 if (la->la_options) {
231 env_setenv(bootvar_flags,la->la_options,ENV_FLG_BUILTIN);
233 else {
234 env_delenv(bootvar_flags);
238 * Banzai! Run the program.
241 if ((la->la_flags & LOADFLG_EXECUTE) &&
242 (la->la_entrypt != 0)) {
243 cfe_go(la);
246 return 0;