GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / applets / test.c
blobc6d22b3bf6b005bc3914dfbe60c315fb55eaa2ef
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * API test program File: test.c
6 * Small program to test CFE's external API
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_printf.h"
50 #include "lib_string.h"
51 #include "cfe_api.h"
53 int conhandle;
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
68 * Input parameters:
69 * buffer - pointer to data
70 * length - number of characters to write
72 * Return value:
73 * number of characters written or <0 if error
74 ********************************************************************* */
76 static int console_write(unsigned char *buffer,int length)
78 int res;
81 * Do nothing if no console
84 if (conhandle == -1) return -1;
87 * Write text to device
90 for (;;) {
91 res = cfe_write(conhandle,buffer,length);
92 if (res < 0) break;
93 buffer += res;
94 length -= res;
95 if (length == 0) break;
98 if (res < 0) return -1;
99 return 0;
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"
110 * Input parameters:
111 * str - string to write
113 * Return value:
114 * number of characters written
115 ********************************************************************* */
117 static int console_xprint(const char *str)
119 int count = 0;
120 int len;
121 const char *p;
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);
128 count += (p-str);
129 str = p + 1;
132 len = strlen(str);
133 console_write((char *) str, len);
134 count += len;
136 return count;
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;
145 char str[100];
146 cfe_fwinfo_t info;
147 int idx;
148 int res;
149 uint64_t start,length,type;
151 xprinthook = console_xprint;
153 cfe_init(handle,ept);
155 conhandle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
157 str[0] = 0;
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);
163 idx = 0;
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");
175 for (;;) {
176 if ((res = cfe_enummem(idx,1,&start,&length,&type) != 0)) break;
177 xprintf("Memory at %016llX length %016llX type %ld\n",
178 start,length,type);
179 idx++;
182 xprintf("Exiting to CFE\n\n");
184 cfe_exit(CFE_FLG_WARMSTART,0);
186 (*reboot)();