1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Main Module File: cfe_main.c
6 * This module contains the main "C" routine for CFE and
7 * the main processing loop. There should not be any board-specific
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"
56 #include "cfe_device.h"
57 #include "cfe_console.h"
58 #include "cfe_timer.h"
61 #include "ui_command.h"
65 #include "exception.h"
67 #include "bsp_config.h"
79 /* *********************************************************************
81 ********************************************************************* */
83 #ifndef CFG_STACK_SIZE
84 #define STACK_SIZE 8192
86 #define STACK_SIZE ((CFG_STACK_SIZE+1023) & ~1023)
89 /* *********************************************************************
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);
106 extern int ui_init_vapicmds(void);
109 #if CFG_VENDOR_EXTENSIONS
110 extern int ui_init_vendorcmds(void);
113 void cfe_command_restart(uint64_t status
);
115 extern segtable_t
*_getsegtbl(void);
117 extern const char *builddate
;
118 extern const char *builduser
;
121 extern int altcpu_cmd_start(uint64_t,uint64_t *);
122 extern int altcpu_cmd_stop(uint64_t);
126 /* *********************************************************************
128 ********************************************************************* */
130 const char *cfe_boardname
= CFG_BOARDNAME
;
131 unsigned int cfe_startflags
=
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.
149 ********************************************************************* */
151 static void cfe_setup_default_env(void)
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
);
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 /* *********************************************************************
172 * Call all the other UI initialization modules. Each of these
173 * modules usually calls back to the UI dispatcher to add command
181 ********************************************************************* */
186 #define OPTIONAL(x) x
189 static void cfe_init_ui(void)
193 OPTIONAL(ui_init_envcmds());
194 OPTIONAL(ui_init_devcmds());
199 OPTIONAL(ui_init_memcmds());
204 OPTIONAL(ui_init_examcmds());
210 #if CFG_VENDOR_EXTENSIONS
211 ui_init_vendorcmds();
214 OPTIONAL(ui_init_misccmds());
219 /* *********************************************************************
222 * Display a string on the board's LED display, if it has one.
223 * This routine depends on the board-support package to
224 * include a "driver" to write to the actual LED, if the board
225 * does not have one this routine will do nothing.
227 * The LEDs are written at various places in the initialization
228 * sequence, to debug board problems.
231 * leds - pointer to four-character ASCII string
235 ********************************************************************* */
237 void cfe_ledstr(const char *leds
)
241 val
= ((((unsigned int) leds
[0]) << 24) |
242 (((unsigned int) leds
[1]) << 16) |
243 (((unsigned int) leds
[2]) << 8) |
244 ((unsigned int) leds
[3]));
250 /* *********************************************************************
253 * Print out the CFE startup message and copyright notice
260 ********************************************************************* */
263 static void cfe_say_hello(void)
266 xprintf("CFE version %s based on BBP %d.%d.%d"
267 #ifdef CFE_VER_RELEASE
270 " for %s (%s)\n", EPI_VERSION_STR
,
271 CFE_VER_MAJOR
,CFE_VER_MINOR
,CFE_VER_BUILD
,
272 #ifdef CFE_VER_RELEASE
297 xprintf("Build Date: %s (%s)\n",builddate
,builduser
);
298 xprintf("Copyright (C) 2000-2008 Broadcom Corporation.\n");
303 /* *********************************************************************
306 * Restart CFE from scratch, jumping back to the boot vector.
313 ********************************************************************* */
315 void cfe_restart(void)
321 /* *********************************************************************
324 * Start a user program
331 ********************************************************************* */
332 void cfe_start(unsigned long ept
)
339 /* *********************************************************************
342 * Display startup memory configuration messages
349 ********************************************************************* */
351 static void cfe_startup_info(void)
355 segtbl
= _getsegtbl();
356 xprintf("CPU type 0x%X: ",(uint32_t)cpu_prid
);
357 if (cfe_cpu_speed
< 1000000) xprintf("%dKHz\n",cfe_cpu_speed
/1000);
358 else xprintf("%dMHz\n",cfe_cpu_speed
/1000000);
359 xprintf("Tot mem: %u KBytes\n", mem_totalsize
);
362 xprintf("CFE mem: 0x%08X - 0x%08X (%d)\n",
363 (uint32_t) mem_bottomofmem
,
364 (uint32_t) mem_topofmem
,
365 (uint32_t) mem_topofmem
-mem_bottomofmem
);
366 xprintf("Data: 0x%08X - 0x%08X (%d)\n",
367 (uint32_t) (segtbl
[R_SEG_FDATA
] + mem_datareloc
),
368 (uint32_t) (segtbl
[R_SEG_EDATA
] + mem_datareloc
),
369 (uint32_t) (segtbl
[R_SEG_EDATA
] - segtbl
[R_SEG_FDATA
]));
370 xprintf("BSS: 0x%08X - 0x%08X (%d)\n",
371 (uint32_t) (segtbl
[R_SEG_FBSS
] + mem_datareloc
),
372 (uint32_t) (segtbl
[R_SEG_END
] + mem_datareloc
),
373 (uint32_t) (segtbl
[R_SEG_END
] - segtbl
[R_SEG_FBSS
]));
374 xprintf("Heap: 0x%08X - 0x%08X (%d)\n",
375 (uint32_t)(mem_heapstart
),
376 (uint32_t)(mem_heapstart
+ (CFG_HEAP_SIZE
*1024)),
377 (CFG_HEAP_SIZE
*1024));
378 xprintf("Stack: 0x%08X - 0x%08X (%d)\n",
379 (uint32_t)(mem_heapstart
+ (CFG_HEAP_SIZE
*1024)),
380 (uint32_t)(mem_heapstart
+ (CFG_HEAP_SIZE
*1024) + STACK_SIZE
),
382 xprintf("Text: 0x%08X - 0x%08X (%d)\n",
383 (uint32_t)mem_textbase
,
384 (uint32_t)(mem_textbase
+mem_textsize
),
385 (uint32_t) mem_textsize
);
386 #if !CFG_MINIMAL_SIZE
387 xprintf("Boot: 0x%08X - 0x%08X\n",
388 mem_bootarea_start
,mem_bootarea_start
+mem_bootarea_size
);
389 xprintf("Reloc: I:%08X - D:%08X\n",
390 (uint32_t) mem_textreloc
,(uint32_t) mem_datareloc
);
395 /* *********************************************************************
398 * Process automatic commands at startup
405 ********************************************************************* */
407 static void cfe_autostart(void)
413 env
= env_getenv("STARTUP");
416 while (console_status()) {
418 if (ch
== 3) noauto
= TRUE
; /* Ctrl-C means no auto */
422 xprintf("Startup canceled\n");
429 /* *********************************************************************
432 * It's gotta start somewhere.
439 ********************************************************************* */
441 void cfe_main(int a
,int b
)
445 * By the time this routine is called, the following things have
448 * 1. The processor(s) is(are) initialized.
449 * 2. The caches are initialized.
450 * 3. The memory controller is initialized.
451 * 4. BSS has been zeroed.
452 * 5. The data has been moved to R/W space.
453 * 6. The "C" Stack has been initialized.
456 cfe_bg_init(); /* init background processing */
458 cfe_timer_init(); /* Timer process */
459 cfe_bg_add(cfe_device_poll
,NULL
);
462 * Initialize the memory allocator
466 KMEMINIT((unsigned char *) (uintptr_t) mem_heapstart
,
467 ((CFG_HEAP_SIZE
)*1024));
470 * Initialize the console. It is done before the other devices
471 * get turned on. The console init also sets the variable that
472 * contains the CPU speed.
476 board_console_init();
479 * Set up the exception vectors
482 cfe_setup_exceptions();
492 * Initialize the other devices.
497 xprintf("CFE XIP\n");
499 xprintf("Init Arena\n");
503 if (cfe_startflags
& CFE_INIT_PCI
) {
504 pci_flags_t flags
= PCI_FLG_NORMAL
| PCI_FLG_LDT_PREFETCH
;
507 extern cons_t pci_optnames
[];
509 flags
= PCI_FLG_NORMAL
| PCI_FLG_LDT_PREFETCH
;
511 flags
|= PCI_FLG_LDT_REV_017
;
513 str
= env_getenv("PCI_OPTIONS");
514 setoptions(pci_optnames
,str
,&flags
);
516 xprintf("Initializing PCI. [%s]\n",str
? str
: "normal");
518 pci_configure(flags
);
523 xprintf("Init Devs.\n");
528 cfe_setup_default_env();
541 /* *********************************************************************
542 * cfe_command_restart()
544 * This routine is called when an application wants to restart
545 * the firmware's command processor. Reopen the console and
546 * jump back into the command loop.
549 * status - A0 value of program returning to firmware
553 ********************************************************************* */
555 void cfe_command_restart(uint64_t status
)
558 * Stop alternate CPU(s). If they're already stopped, this
559 * command will make sure they're stopped.
567 * Call board reset functions
569 board_device_reset();
584 console_open(console_name
);
587 * Display program return status
590 xprintf("*exit status = %d\n", (int)status
);
593 * Back to processing user commands
600 /* *********************************************************************
603 * This routine reads and processes user commands
610 ********************************************************************* */
612 void cfe_command_loop()
621 prompt
= env_getenv("PROMPT");
624 if (!prompt
) prompt
= "CFE_RAM> ";
626 if (!prompt
) prompt
= "CFE> ";
628 console_readline(prompt
,buffer
,sizeof(buffer
));
630 status
= ui_docommands(buffer
);
632 if (status
!= CMD_ERR_BLANK
) {
633 xprintf("*** command status = %d\n", status
);