GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / main / cfe_main.c
blob14245ef03a0e4db3cea87b05b0b6c60da5117bd7
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Main Module File: cfe_main.c
5 *
6 * This module contains the main "C" routine for CFE and
7 * the main processing loop. There should not be any board-specific
8 * stuff in here.
9 *
10 * Author: Mitch Lichtenberg (mpl@broadcom.com)
12 *********************************************************************
14 * Copyright 2000,2001,2002,2003
15 * Broadcom Corporation. All rights reserved.
17 * This software is furnished under license and may be used and
18 * copied only in accordance with the following terms and
19 * conditions. Subject to these conditions, you may download,
20 * copy, install, use, modify and distribute modified or unmodified
21 * copies of this software in source and/or binary form. No title
22 * or ownership is transferred hereby.
24 * 1) Any source code used, modified or distributed must reproduce
25 * and retain this copyright notice and list of conditions
26 * as they appear in the source file.
28 * 2) No right is granted to use any trade name, trademark, or
29 * logo of Broadcom Corporation. The "Broadcom Corporation"
30 * name may not be used to endorse or promote products derived
31 * from this software without the prior written permission of
32 * Broadcom Corporation.
34 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
35 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
38 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
39 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
40 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
46 * THE POSSIBILITY OF SUCH DAMAGE.
47 ********************************************************************* */
50 #include "lib_types.h"
51 #include "lib_string.h"
52 #include "lib_malloc.h"
53 #include "lib_printf.h"
55 #include "cfe_iocb.h"
56 #include "cfe_device.h"
57 #include "cfe_console.h"
58 #include "cfe_timer.h"
60 #include "env_subr.h"
61 #include "ui_command.h"
62 #include "cfe_mem.h"
63 #include "cfe.h"
65 #include "exception.h"
67 #include "bsp_config.h"
69 #include "segtable.h"
71 #include "initdata.h"
73 #if CFG_PCI
74 #include "pcivar.h"
75 #endif
77 #include "epivers.h"
79 /* *********************************************************************
80 * Constants
81 ********************************************************************* */
83 #ifndef CFG_STACK_SIZE
84 #define STACK_SIZE 8192
85 #else
86 #define STACK_SIZE ((CFG_STACK_SIZE+1023) & ~1023)
87 #endif
89 /* *********************************************************************
90 * Externs
91 ********************************************************************* */
93 void cfe_main(int,int);
94 extern void cfe_device_poll(void *x);
96 extern int ui_init_envcmds(void);
97 extern int ui_init_devcmds(void);
98 extern int ui_init_netcmds(void);
99 extern int ui_init_memcmds(void);
100 extern int ui_init_loadcmds(void);
101 extern int ui_init_pcicmds(void);
102 extern int ui_init_examcmds(void);
103 extern int ui_init_flashcmds(void);
104 extern int ui_init_misccmds(void);
105 #if CFG_VAPI
106 extern int ui_init_vapicmds(void);
107 #endif
109 #if CFG_VENDOR_EXTENSIONS
110 extern int ui_init_vendorcmds(void);
111 #endif
113 void cfe_command_restart(uint64_t status);
115 extern segtable_t *_getsegtbl(void);
117 extern const char *builddate;
118 extern const char *builduser;
120 #if CFG_MULTI_CPUS
121 extern int altcpu_cmd_start(uint64_t,uint64_t *);
122 extern int altcpu_cmd_stop(uint64_t);
123 #endif
126 /* *********************************************************************
127 * Globals
128 ********************************************************************* */
130 const char *cfe_boardname = CFG_BOARDNAME;
131 unsigned int cfe_startflags =
132 #if CFG_PCI
133 CFE_INIT_PCI |
134 #endif
137 /* *********************************************************************
138 * cfe_setup_default_env()
140 * Initialize the default environment for CFE. These are all
141 * the temporary variables that do not get stored in the NVRAM
142 * but are available to other programs and command-line macros.
144 * Input parameters:
145 * nothing
147 * Return value:
148 * nothing
149 ********************************************************************* */
151 static void cfe_setup_default_env(void)
153 char buffer[80];
155 xsprintf(buffer,"%d.%d.%d",CFE_VER_MAJOR,CFE_VER_MINOR,CFE_VER_BUILD);
156 env_setenv("CFE_VERSION",buffer,ENV_FLG_BUILTIN | ENV_FLG_READONLY);
158 if (cfe_boardname) {
159 env_setenv("CFE_BOARDNAME",(char *) cfe_boardname,
160 ENV_FLG_BUILTIN | ENV_FLG_READONLY);
163 xsprintf(buffer,"%d",mem_totalsize);
164 env_setenv("CFE_MEMORYSIZE",buffer,ENV_FLG_BUILTIN | ENV_FLG_READONLY);
169 /* *********************************************************************
170 * cfe_init_ui()
172 * Call all the other UI initialization modules. Each of these
173 * modules usually calls back to the UI dispatcher to add command
174 * tables.
176 * Input parameters:
177 * nothing
179 * Return value:
180 * nothing
181 ********************************************************************* */
183 #if CFG_MINIMAL_SIZE
184 #define OPTIONAL(x)
185 #else
186 #define OPTIONAL(x) x
187 #endif
189 static void cfe_init_ui(void)
191 ui_init_cmddisp();
193 OPTIONAL(ui_init_envcmds());
194 //OPTIONAL(ui_init_devcmds());
195 ui_init_devcmds();
196 #if CFG_NETWORK
197 ui_init_netcmds();
198 #endif
199 ui_init_loadcmds();
200 OPTIONAL(ui_init_memcmds());
202 #if CFG_PCI
203 ui_init_pcicmds();
204 #endif
205 OPTIONAL(ui_init_examcmds());
206 ui_init_flashcmds();
207 #if CFG_VAPI
208 ui_init_vapicmds();
209 #endif
211 #if CFG_VENDOR_EXTENSIONS
212 ui_init_vendorcmds();
213 #endif
215 OPTIONAL(ui_init_misccmds());
220 /* *********************************************************************
221 * cfe_ledstr(leds)
223 * Display a string on the board's LED display, if it has one.
224 * This routine depends on the board-support package to
225 * include a "driver" to write to the actual LED, if the board
226 * does not have one this routine will do nothing.
228 * The LEDs are written at various places in the initialization
229 * sequence, to debug board problems.
231 * Input parameters:
232 * leds - pointer to four-character ASCII string
234 * Return value:
235 * nothing
236 ********************************************************************* */
238 void cfe_ledstr(const char *leds)
240 unsigned int val;
242 val = ((((unsigned int) leds[0]) << 24) |
243 (((unsigned int) leds[1]) << 16) |
244 (((unsigned int) leds[2]) << 8) |
245 ((unsigned int) leds[3]));
247 cfe_leds(val);
251 /* *********************************************************************
252 * cfe_say_hello()
254 * Print out the CFE startup message and copyright notice
256 * Input parameters:
257 * nothing
259 * Return value:
260 * nothing
261 ********************************************************************* */
264 static void cfe_say_hello(void)
266 xprintf("\n\n");
267 xprintf("CFE version %s based on BBP %d.%d.%d"
268 #ifdef CFE_VER_RELEASE
269 ".%d"
270 #endif
271 " for %s (%s)\n", EPI_VERSION_STR,
272 CFE_VER_MAJOR,CFE_VER_MINOR,CFE_VER_BUILD,
273 #ifdef CFE_VER_RELEASE
274 CFE_VER_RELEASE,
275 #endif
276 cfe_boardname,
277 #ifdef __long64
278 "64bit,"
279 #else
280 "32bit,"
281 #endif
282 #if CFG_MULTI_CPUS
283 "MP,"
284 #else
285 "SP,"
286 #endif
287 #ifdef __MIPSEL
288 "LE"
289 #endif
290 #ifdef __MIPSEB
291 "BE"
292 #endif
293 #if CFG_VAPI
294 ",VAPI"
295 #endif
298 xprintf("Build Date: %s (%s)\n",builddate,builduser);
299 xprintf("Copyright (C) 2000-2008 Broadcom Corporation.\n");
300 xprintf("\n");
304 /* *********************************************************************
305 * cfe_restart()
307 * Restart CFE from scratch, jumping back to the boot vector.
309 * Input parameters:
310 * nothing
312 * Return value:
313 * does not return
314 ********************************************************************* */
316 void cfe_restart(void)
318 _exc_restart();
322 /* *********************************************************************
323 * cfe_start(ept)
325 * Start a user program
327 * Input parameters:
328 * ept - entry point
330 * Return value:
331 * nothing
332 ********************************************************************* */
333 void cfe_start(unsigned long ept)
335 SETLEDS("RUN!");
336 cfe_launch(ept);
340 /* *********************************************************************
341 * cfe_startup_info()
343 * Display startup memory configuration messages
345 * Input parameters:
346 * nothing
348 * Return value:
349 * nothing
350 ********************************************************************* */
352 static void cfe_startup_info(void)
354 segtable_t *segtbl;
356 segtbl = _getsegtbl();
357 xprintf("CPU type 0x%X: ",(uint32_t)cpu_prid);
358 if (cfe_cpu_speed < 1000000) xprintf("%dKHz\n",cfe_cpu_speed/1000);
359 else xprintf("%dMHz\n",cfe_cpu_speed/1000000);
360 xprintf("Tot mem: %u KBytes\n", mem_totalsize);
362 xprintf("\n");
363 xprintf("CFE mem: 0x%08X - 0x%08X (%d)\n",
364 (uint32_t) mem_bottomofmem,
365 (uint32_t) mem_topofmem,
366 (uint32_t) mem_topofmem-mem_bottomofmem);
367 xprintf("Data: 0x%08X - 0x%08X (%d)\n",
368 (uint32_t) (segtbl[R_SEG_FDATA] + mem_datareloc),
369 (uint32_t) (segtbl[R_SEG_EDATA] + mem_datareloc),
370 (uint32_t) (segtbl[R_SEG_EDATA] - segtbl[R_SEG_FDATA]));
371 xprintf("BSS: 0x%08X - 0x%08X (%d)\n",
372 (uint32_t) (segtbl[R_SEG_FBSS] + mem_datareloc),
373 (uint32_t) (segtbl[R_SEG_END] + mem_datareloc),
374 (uint32_t) (segtbl[R_SEG_END] - segtbl[R_SEG_FBSS]));
375 xprintf("Heap: 0x%08X - 0x%08X (%d)\n",
376 (uint32_t)(mem_heapstart),
377 (uint32_t)(mem_heapstart + (CFG_HEAP_SIZE*1024)),
378 (CFG_HEAP_SIZE*1024));
379 xprintf("Stack: 0x%08X - 0x%08X (%d)\n",
380 (uint32_t)(mem_heapstart + (CFG_HEAP_SIZE*1024)),
381 (uint32_t)(mem_heapstart + (CFG_HEAP_SIZE*1024) + STACK_SIZE),
382 STACK_SIZE);
383 xprintf("Text: 0x%08X - 0x%08X (%d)\n",
384 (uint32_t)mem_textbase,
385 (uint32_t)(mem_textbase+mem_textsize),
386 (uint32_t) mem_textsize);
387 #if !CFG_MINIMAL_SIZE
388 xprintf("Boot: 0x%08X - 0x%08X\n",
389 mem_bootarea_start,mem_bootarea_start+mem_bootarea_size);
390 xprintf("Reloc: I:%08X - D:%08X\n",
391 (uint32_t) mem_textreloc,(uint32_t) mem_datareloc);
392 #endif
396 /* *********************************************************************
397 * cfe_autostart()
399 * Process automatic commands at startup
401 * Input parameters:
402 * nothing
404 * Return value:
405 * nothing
406 ********************************************************************* */
408 static void cfe_autostart(void)
410 char *env;
411 int noauto = 0;
412 char ch = 0;
414 env = env_getenv("STARTUP");
415 if (!env) return;
417 while (console_status()) {
418 console_read(&ch,1);
419 if (ch == 3) noauto = TRUE; /* Ctrl-C means no auto */
422 if (noauto) {
423 xprintf("Startup canceled\n");
424 return;
427 ui_docommands(env);
430 /* *********************************************************************
431 * cfe_main(a,b)
433 * It's gotta start somewhere.
435 * Input parameters:
436 * a,b - not used
438 * Return value:
439 * does not return
440 ********************************************************************* */
442 void cfe_main(int a,int b)
446 * By the time this routine is called, the following things have
447 * already been done:
449 * 1. The processor(s) is(are) initialized.
450 * 2. The caches are initialized.
451 * 3. The memory controller is initialized.
452 * 4. BSS has been zeroed.
453 * 5. The data has been moved to R/W space.
454 * 6. The "C" Stack has been initialized.
457 cfe_bg_init(); /* init background processing */
458 cfe_attach_init();
459 cfe_timer_init(); /* Timer process */
460 cfe_bg_add(cfe_device_poll,NULL);
463 * Initialize the memory allocator
466 SETLEDS("KMEM");
467 KMEMINIT((unsigned char *) (uintptr_t) mem_heapstart,
468 ((CFG_HEAP_SIZE)*1024));
471 * Initialize the console. It is done before the other devices
472 * get turned on. The console init also sets the variable that
473 * contains the CPU speed.
476 SETLEDS("CONS");
477 board_console_init();
480 * Set up the exception vectors
483 cfe_setup_exceptions();
486 * Say hello.
489 SETLEDS("CIOK");
490 cfe_say_hello();
493 * Initialize the other devices.
496 SETLEDS("AREN");
497 #if CFG_XIP
498 xprintf("CFE XIP\n");
499 #endif
500 xprintf("Init Arena\n");
501 cfe_arena_init();
503 #if CFG_PCI
504 if (cfe_startflags & CFE_INIT_PCI) {
505 pci_flags_t flags = PCI_FLG_NORMAL | PCI_FLG_LDT_PREFETCH;
506 #ifndef EB332
507 char *str;
508 extern cons_t pci_optnames[];
510 flags = PCI_FLG_NORMAL | PCI_FLG_LDT_PREFETCH;
511 #if CFG_LDT_REV_017
512 flags |= PCI_FLG_LDT_REV_017;
513 #endif
514 str = env_getenv("PCI_OPTIONS");
515 setoptions(pci_optnames,str,&flags);
517 xprintf("Initializing PCI. [%s]\n",str ? str : "normal");
518 #endif
519 pci_configure(flags);
521 #endif
523 SETLEDS("DEVI");
524 xprintf("Init Devs.\n");
525 board_device_init();
527 cfe_startup_info();
528 SETLEDS("ENVI");
529 cfe_setup_default_env();
531 xprintf("\n");
533 cfe_init_ui();
535 board_final_init();
537 cfe_autostart();
539 cfe_command_loop();
542 /* *********************************************************************
543 * cfe_command_restart()
545 * This routine is called when an application wants to restart
546 * the firmware's command processor. Reopen the console and
547 * jump back into the command loop.
549 * Input parameters:
550 * status - A0 value of program returning to firmware
552 * Return value:
553 * does not return
554 ********************************************************************* */
556 void cfe_command_restart(uint64_t status)
559 * Stop alternate CPU(s). If they're already stopped, this
560 * command will make sure they're stopped.
563 #if CFG_MULTI_CPUS
564 altcpu_cmd_stop(1);
565 #endif
568 * Call board reset functions
570 board_device_reset();
573 * Reset devices
575 cfe_device_reset();
578 * Reset timers
580 cfe_timer_init();
583 * Reopen console
585 console_open(console_name);
588 * Display program return status
591 xprintf("*exit status = %d\n", (int)status);
594 * Back to processing user commands
596 cfe_command_loop();
601 /* *********************************************************************
602 * cfe_command_loop()
604 * This routine reads and processes user commands
606 * Input parameters:
607 * nothing
609 * Return value:
610 * does not return
611 ********************************************************************* */
613 void cfe_command_loop()
615 char buffer[300];
616 int status;
617 char *prompt;
619 SETLEDS("CFE ");
621 for (;;) {
622 prompt = env_getenv("PROMPT");
623 #if CFG_RAMAPP
624 SETLEDS("CFE*");
625 if (!prompt) prompt = "CFE_RAM> ";
626 #else
627 if (!prompt) prompt = "CFE> ";
628 #endif
629 console_readline(prompt,buffer,sizeof(buffer));
631 status = ui_docommands(buffer);
633 if (status != CMD_ERR_BLANK) {
634 xprintf("*** command status = %d\n", status);