1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * API test program File: test.c
6 * Small program to test CFE's external API
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_printf.h"
50 #include "lib_string.h"
56 void appletmain(unsigned long handle
,unsigned long vector
,
57 unsigned long reserved
,unsigned long seal
);
62 /* *********************************************************************
63 * console_write(buffer,length)
65 * Write text to the console. If the console is not open and
66 * we're "saving" text, put the text on the in-memory queue
69 * buffer - pointer to data
70 * length - number of characters to write
73 * number of characters written or <0 if error
74 ********************************************************************* */
76 static int console_write(unsigned char *buffer
,int length
)
81 * Do nothing if no console
84 if (conhandle
== -1) return -1;
87 * Write text to device
91 res
= cfe_write(conhandle
,buffer
,length
);
95 if (length
== 0) break;
98 if (res
< 0) return -1;
103 /* *********************************************************************
104 * console_xprint(str)
106 * printf callback for the console device. the "xprintf"
107 * routine ends up calling this. This routine also cooks the
108 * output, turning "\n" into "\r\n"
111 * str - string to write
114 * number of characters written
115 ********************************************************************* */
117 static int console_xprint(const char *str
)
123 /* Convert CR to CRLF as we write things out */
125 while ((p
= strchr(str
,'\n'))) {
126 console_write((char *) str
,p
-str
);
127 console_write("\r\n",2);
133 console_write((char *) str
, len
);
141 void appletmain(unsigned long handle
,unsigned long vector
,
142 unsigned long ept
,unsigned long seal
)
144 void (*reboot
)(void) = (void *) (uintptr_t) (int) 0xBFC00000;
149 uint64_t start
,length
,type
;
151 xprinthook
= console_xprint
;
153 cfe_init(handle
,ept
);
155 conhandle
= cfe_getstdhandle(CFE_STDHANDLE_CONSOLE
);
158 cfe_getenv("BOOT_CONSOLE",str
,sizeof(str
));
160 xprintf("Hello, world. Console = %s\n",str
);
161 xprintf("API Seal = %08X\n",(int)seal
);
162 xprintf("Entrypoint=%08X Handle=%08X\n",(int)ept
,(int)handle
);
165 cfe_getfwinfo(&info
);
166 xprintf("CFE version: %08llX\n",info
.fwi_version
);
167 xprintf("Flags: %08llX\n",info
.fwi_flags
);
168 xprintf("Total memory: %08llX\n",info
.fwi_totalmem
);
169 xprintf("Board ID: %08llX\n",info
.fwi_boardid
);
170 xprintf("Bootarea VA: %08llX\n",info
.fwi_bootarea_va
);
171 xprintf("Bootarea PA: %08llX\n",info
.fwi_bootarea_pa
);
172 xprintf("Bootarea Size: %08llX\n",info
.fwi_bootarea_size
);
174 xprintf("Memory map:\n");
176 if ((res
= cfe_enummem(idx
,1,&start
,&length
,&type
) != 0)) break;
177 xprintf("Memory at %016llX length %016llX type %ld\n",
182 xprintf("Exiting to CFE\n\n");
184 cfe_exit(CFE_FLG_WARMSTART
,0);