1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * Test commands File: cfe_tests.c 5 * 6 * A temporary sandbox for misc test routines and commands. 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 "cfe.h" 49 50#include "cfe_error.h" 51 52#include "env_subr.h" 53#include "ui_command.h" 54 55#include "bsp_config.h" 56 57#include "cfe_mem.h" 58 59int ui_init_testcmds(void); 60static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[]); 61#if CFG_DOWNLOAD 62static int ui_cmd_config1250(ui_cmdline_t *cmd,int argc,char *argv[]); 63#endif 64 65int ui_init_testcmds(void) 66{ 67 68 cmd_addcmd("test timer", 69 ui_cmd_timertest, 70 NULL, 71 "Test the timer", 72 "test timer", 73 ""); 74#if CFG_DOWNLOAD 75 cmd_addcmd("test bcm1250", 76 ui_cmd_config1250, 77 NULL, 78 "Configure a bcm1250 as a PCI device", 79 "test bcm1250 device-name [file-name]\n\n" 80 "Download code to the specified 1250-based PCI device", 81 "" 82 ); 83#endif 84 85 return 0; 86} 87 88 89 90 91#if CFG_DOWNLOAD 92 93#include "net_ebuf.h" 94#include "net_api.h" 95#include "addrspace.h" 96#include "cfe_loader.h" 97extern cfe_loadargs_t cfe_loadargs; 98 99/* Staging buffer for downloaded files. See ui_flash for rationale. */ 100#define FILE_STAGING_BUFFER (1024*1024) /* 1MB line */ 101#define FILE_STAGING_BUFFER_SIZE (4048*1024) 102 103/* Base and bound of compiled-in downloadable image */ 104extern void download_start(void), download_end(void); 105 106static int ui_cmd_config1250(ui_cmdline_t *cmd,int argc,char *argv[]) 107{ 108 char *tok; 109 int fh; 110 uint8_t *base; 111 int len; 112 int res; 113 114 tok = cmd_getarg(cmd, 0); 115 if (!tok) { 116 return ui_showusage(cmd); 117 } 118 119 if (argc > 1) { 120 char *fname; 121 cfe_loadargs_t *la = &cfe_loadargs; 122 int res; 123 124 fname = cmd_getarg(cmd, 1); 125 if (!fname) { 126 return ui_showusage(cmd); 127 } 128 129 /* Get the file using tftp and read it into a known location. */ 130 131 /* (From ui_flash.c): 132 * We can't allocate the space from the heap to store the 133 * file to download, because the heap may not be big enough. 134 * So, grab some unallocated memory at the 1MB line (we could 135 * also calculate something, but this will do for now). 136 * We assume the downloadable file will be no bigger than 4MB. 137 */ 138 139 /* Fill out the loadargs */ 140 141 la->la_flags = LOADFLG_NOISY; 142 143 la->la_device = (char *) net_getparam(NET_DEVNAME); 144 la->la_filesys = "tftp"; 145 la->la_filename = fname; 146 147 /* Temporary: use a fixed memory buffer. */ 148 la->la_address = KERNADDR(FILE_STAGING_BUFFER); 149 la->la_maxsize = FILE_STAGING_BUFFER_SIZE;; 150 la->la_flags |= LOADFLG_SPECADDR; 151 152 la->la_options = NULL; 153 154 xprintf("Loader:raw Filesys:%s Dev:%s File:%s Options:%s\n", 155 la->la_filesys, la->la_device, la->la_filename, la->la_options); 156 157 res = cfe_load_program("raw", la); 158 if (res < 0) { 159 xprintf("Could not load %s\n", fname); 160 return res; 161 } 162 163 base = HSADDR2PTR(la->la_address); 164 len = res; 165 } 166 else { 167 /* This code casts a function pointer to a byte pointer, which is 168 suspect in ANSI C but appears to work with the gnu MIPS tool 169 chain. Changing the externs to, e.g., uint8_t * does not work 170 with PIC code (generates relocation errors). */ 171 172 base = (uint8_t *)download_start; 173 len = (uint8_t *)download_end - (uint8_t *)download_start; 174 } 175 xprintf("PCI download: base %p len %d\n", base, len); 176 177 fh = cfe_open(tok); 178 if (fh < 0) { 179 xprintf("Could not open device: %s\n", cfe_errortext(fh)); 180 return fh; 181 } 182 183 res = cfe_write(fh, PTR2HSADDR((unsigned char *)base), len); 184 if (res != 0) { 185 xprintf("Could not download device: %s\n", cfe_errortext(res)); 186 } 187 188 cfe_close(fh); 189 190 return res; 191} 192#endif /* CFG_DOWNLOAD */ 193 194 195 196 197static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[]) 198{ 199 int64_t t; 200 201 t = cfe_ticks; 202 203 while (!console_status()) { 204 cfe_sleep(CFE_HZ); 205 if (t != cfe_ticks) { 206 xprintf("Time is %lld\n",cfe_ticks); 207 t = cfe_ticks; 208 } 209 } 210 211 return 0; 212} 213 214 215 216 217