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());
200 OPTIONAL(ui_init_memcmds());
205 OPTIONAL(ui_init_examcmds());
211 #if CFG_VENDOR_EXTENSIONS
212 ui_init_vendorcmds();
215 OPTIONAL(ui_init_misccmds());
220 /* *********************************************************************
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.
232 * leds - pointer to four-character ASCII string
236 ********************************************************************* */
238 void cfe_ledstr(const char *leds
)
242 val
= ((((unsigned int) leds
[0]) << 24) |
243 (((unsigned int) leds
[1]) << 16) |
244 (((unsigned int) leds
[2]) << 8) |
245 ((unsigned int) leds
[3]));
251 /* *********************************************************************
254 * Print out the CFE startup message and copyright notice
261 ********************************************************************* */
264 static void cfe_say_hello(void)
267 xprintf("CFE version %s based on BBP %d.%d.%d"
268 #ifdef CFE_VER_RELEASE
271 " for %s (%s)\n", EPI_VERSION_STR
,
272 CFE_VER_MAJOR
,CFE_VER_MINOR
,CFE_VER_BUILD
,
273 #ifdef CFE_VER_RELEASE
298 xprintf("Build Date: %s (%s)\n",builddate
,builduser
);
299 xprintf("Copyright (C) 2000-2008 Broadcom Corporation.\n");
304 /* *********************************************************************
307 * Restart CFE from scratch, jumping back to the boot vector.
314 ********************************************************************* */
316 void cfe_restart(void)
322 /* *********************************************************************
325 * Start a user program
332 ********************************************************************* */
333 void cfe_start(unsigned long ept
)
340 /* *********************************************************************
343 * Display startup memory configuration messages
350 ********************************************************************* */
352 static void cfe_startup_info(void)
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
);
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
),
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
);
396 /* *********************************************************************
399 * Process automatic commands at startup
406 ********************************************************************* */
408 static void cfe_autostart(void)
414 env
= env_getenv("STARTUP");
417 while (console_status()) {
419 if (ch
== 3) noauto
= TRUE
; /* Ctrl-C means no auto */
423 xprintf("Startup canceled\n");
430 /* *********************************************************************
433 * It's gotta start somewhere.
440 ********************************************************************* */
442 void cfe_main(int a
,int b
)
446 * By the time this routine is called, the following things have
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 */
459 cfe_timer_init(); /* Timer process */
460 cfe_bg_add(cfe_device_poll
,NULL
);
463 * Initialize the memory allocator
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.
477 board_console_init();
480 * Set up the exception vectors
483 cfe_setup_exceptions();
493 * Initialize the other devices.
498 xprintf("CFE XIP\n");
500 xprintf("Init Arena\n");
504 if (cfe_startflags
& CFE_INIT_PCI
) {
505 pci_flags_t flags
= PCI_FLG_NORMAL
| PCI_FLG_LDT_PREFETCH
;
508 extern cons_t pci_optnames
[];
510 flags
= PCI_FLG_NORMAL
| PCI_FLG_LDT_PREFETCH
;
512 flags
|= PCI_FLG_LDT_REV_017
;
514 str
= env_getenv("PCI_OPTIONS");
515 setoptions(pci_optnames
,str
,&flags
);
517 xprintf("Initializing PCI. [%s]\n",str
? str
: "normal");
519 pci_configure(flags
);
524 xprintf("Init Devs.\n");
529 cfe_setup_default_env();
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.
550 * status - A0 value of program returning to firmware
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.
568 * Call board reset functions
570 board_device_reset();
585 console_open(console_name
);
588 * Display program return status
591 xprintf("*exit status = %d\n", (int)status
);
594 * Back to processing user commands
601 /* *********************************************************************
604 * This routine reads and processes user commands
611 ********************************************************************* */
613 void cfe_command_loop()
622 prompt
= env_getenv("PROMPT");
625 if (!prompt
) prompt
= "CFE_RAM> ";
627 if (!prompt
) prompt
= "CFE> ";
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
);