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 (mpl@broadcom.com) 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((char *) str,p-str); 127 console_write("\r\n",2); 128 count += (p-str); 129 str = p + 1; 130 } 131 132 len = strlen(str); 133 console_write((char *) str, len); 134 count += len; 135 136 return count; 137} 138 139 140 141void appletmain(unsigned long handle,unsigned long vector, 142 unsigned long ept,unsigned long seal) 143{ 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; 150 151 xprinthook = console_xprint; 152 153 cfe_init(handle,ept); 154 155 conhandle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE); 156 157 str[0] = 0; 158 cfe_getenv("BOOT_CONSOLE",str,sizeof(str)); 159 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; 164 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); 173 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++; 180 } 181 182 xprintf("Exiting to CFE\n\n"); 183 184 cfe_exit(CFE_FLG_WARMSTART,0); 185 186 (*reboot)(); 187 188} 189