1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * API test program File: test.c 5 * 6 * Small program to test CFE's external API 7 * 8 * Author: Mitch Lichtenberg 9 * 10 ********************************************************************* 11 * 12 * Copyright 2000,2001,2002,2003 13 * Broadcom Corporation. All rights reserved. 14 * 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. 21 * 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. 25 * 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. 31 * 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 ********************************************************************* */ 46 47 48#include "lib_types.h" 49#include "lib_printf.h" 50#include "lib_string.h" 51#include "cfe_api.h" 52 53int conhandle; 54 55 56void appletmain(unsigned long handle,unsigned long vector, 57 unsigned long reserved,unsigned long seal); 58 59 60 61 62/* ********************************************************************* 63 * console_write(buffer,length) 64 * 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 67 * 68 * Input parameters: 69 * buffer - pointer to data 70 * length - number of characters to write 71 * 72 * Return value: 73 * number of characters written or <0 if error 74 ********************************************************************* */ 75 76static int console_write(unsigned char *buffer,int length) 77{ 78 int res; 79 80 /* 81 * Do nothing if no console 82 */ 83 84 if (conhandle == -1) return -1; 85 86 /* 87 * Write text to device 88 */ 89 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; 96 } 97 98 if (res < 0) return -1; 99 return 0; 100} 101 102 103/* ********************************************************************* 104 * console_xprint(str) 105 * 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" 109 * 110 * Input parameters: 111 * str - string to write 112 * 113 * Return value: 114 * number of characters written 115 ********************************************************************* */ 116 117static int console_xprint(const char *str) 118{ 119 int count = 0; 120 int len; 121 const char *p; 122 123 /* Convert CR to CRLF as we write things out */ 124 125 while ((p = strchr(str,'\n'))) { 126 console_write((unsigned char *) str,p-str); 127 console_write((unsigned char *)"\r\n",2); 128 count += (p-str); 129 str = p + 1; 130 } 131 132 len = strlen(str); 133 console_write((unsigned char *) str, len); 134 count += len; 135 136 return count; 137} 138 139 140#if 0 141static int myxprinthook(const char *str) 142{ 143 int count = 0; 144 int len; 145 const char *p; 146 147 /* Convert CR to CRLF as we write things out */ 148 149 while ((p = strchr(str,'\r'))) { 150 cfe_write(conhandle,(char *) str,p-str+1); 151 cfe_write(conhandle,"\n",1); 152 count += (p-str); 153 str = p + 1; 154 } 155 156 len = strlen(str); 157 cfe_write(conhandle,(char *) str, len); 158 count += len; 159 160 return count; 161} 162#endif 163 164void appletmain(unsigned long handle,unsigned long vector, 165 unsigned long ept,unsigned long seal) 166{ 167 void (*reboot)(void) = (void *) (uintptr_t) (int) 0xBFC00000; 168 char str[100]; 169 cfe_fwinfo_t info; 170 int idx; 171 int res; 172 uint64_t start,length,type; 173 174 xprinthook = console_xprint; 175 176 cfe_init(handle,ept); 177 178 conhandle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE); 179 180 str[0] = 0; 181 cfe_getenv("BOOT_CONSOLE",str,sizeof(str)); 182 183 xprintf("Hello, world. Console = %s\n",str); 184 xprintf("API Seal = %08X\n",(int)seal); 185 xprintf("Entrypoint=%08X Handle=%08X\n",(int)ept,(int)handle); 186 idx = 0; 187 188 cfe_getfwinfo(&info); 189 xprintf("CFE version: %08llX\n",info.fwi_version); 190 xprintf("Flags: %08llX\n",info.fwi_flags); 191 xprintf("Total memory: %08llX\n",info.fwi_totalmem); 192 xprintf("Board ID: %08llX\n",info.fwi_boardid); 193 xprintf("Bootarea VA: %08llX\n",info.fwi_bootarea_va); 194 xprintf("Bootarea PA: %08llX\n",info.fwi_bootarea_pa); 195 xprintf("Bootarea Size: %08llX\n",info.fwi_bootarea_size); 196 197 xprintf("Memory map:\n"); 198 for (;;) { 199 if ((res = cfe_enummem(idx,1,&start,&length,&type) != 0)) break; 200 xprintf("Memory at %016llX length %016llX type %ld\n", 201 start,length,type); 202 idx++; 203 } 204 205 xprintf("Exiting to CFE\n\n"); 206 207 cfe_exit(CFE_FLG_WARMSTART,0); 208 209 (*reboot)(); 210 211} 212