RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / arch / mips / cpu / sb1250 / src / cfe_tests.c
blobd1bf980777a691a5e02f5874c343a7cb179068c9
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 (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 ********************************************************************* */
49 #include "lib_types.h"
50 #include "lib_string.h"
51 #include "lib_queue.h"
52 #include "lib_malloc.h"
53 #include "lib_printf.h"
55 #include "cfe_iocb.h"
56 #include "cfe_device.h"
57 #include "cfe_console.h"
58 #include "cfe_devfuncs.h"
59 #include "cfe_timer.h"
60 #include "cfe_ioctl.h"
62 #include "cfe_error.h"
64 #include "env_subr.h"
65 #include "ui_command.h"
66 #include "cfe.h"
68 #include "bsp_config.h"
70 #include "cfe_mem.h"
72 int ui_init_testcmds(void);
73 static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[]);
74 #if CFG_DOWNLOAD
75 static int ui_cmd_config1250(ui_cmdline_t *cmd,int argc,char *argv[]);
76 #endif
78 int ui_init_testcmds(void)
81 cmd_addcmd("test timer",
82 ui_cmd_timertest,
83 NULL,
84 "Test the timer",
85 "test timer",
86 "");
87 #if CFG_DOWNLOAD
88 cmd_addcmd("test bcm1250",
89 ui_cmd_config1250,
90 NULL,
91 "Configure a bcm1250 as a PCI device",
92 "test bcm1250 device-name [file-name]\n\n"
93 "Download code to the specified 1250-based PCI device",
96 #endif
98 return 0;
104 #if CFG_DOWNLOAD
106 #include "net_ebuf.h"
107 #include "net_api.h"
108 #include "addrspace.h"
109 #include "cfe_loader.h"
110 extern cfe_loadargs_t cfe_loadargs;
112 /* Staging buffer for downloaded files. See ui_flash for rationale. */
113 #define FILE_STAGING_BUFFER (1024*1024) /* 1MB line */
114 #define FILE_STAGING_BUFFER_SIZE (4048*1024)
116 /* Base and bound of compiled-in downloadable image */
117 extern void download_start(void), download_end(void);
119 static int ui_cmd_config1250(ui_cmdline_t *cmd,int argc,char *argv[])
121 char *tok;
122 int fh;
123 uint8_t *base;
124 int len;
125 int res;
127 tok = cmd_getarg(cmd, 0);
128 if (!tok) {
129 return ui_showusage(cmd);
132 if (argc > 1) {
133 char *fname;
134 cfe_loadargs_t *la = &cfe_loadargs;
135 int res;
137 fname = cmd_getarg(cmd, 1);
138 if (!fname) {
139 return ui_showusage(cmd);
142 /* Get the file using tftp and read it into a known location. */
144 /* (From ui_flash.c):
145 * We can't allocate the space from the heap to store the
146 * file to download, because the heap may not be big enough.
147 * So, grab some unallocated memory at the 1MB line (we could
148 * also calculate something, but this will do for now).
149 * We assume the downloadable file will be no bigger than 4MB.
152 /* Fill out the loadargs */
154 la->la_flags = LOADFLG_NOISY;
156 la->la_device = (char *) net_getparam(NET_DEVNAME);
157 la->la_filesys = "tftp";
158 la->la_filename = fname;
160 /* Temporary: use a fixed memory buffer. */
161 la->la_address = KERNADDR(FILE_STAGING_BUFFER);
162 la->la_maxsize = FILE_STAGING_BUFFER_SIZE;;
163 la->la_flags |= LOADFLG_SPECADDR;
165 la->la_options = NULL;
167 xprintf("Loader:raw Filesys:%s Dev:%s File:%s Options:%s\n",
168 la->la_filesys, la->la_device, la->la_filename, la->la_options);
170 res = cfe_load_program("raw", la);
171 if (res < 0) {
172 xprintf("Could not load %s\n", fname);
173 return res;
176 base = (uint8_t *)(la->la_address);
177 len = res;
179 else {
180 /* This code casts a function pointer to a byte pointer, which is
181 suspect in ANSI C but appears to work with the gnu MIPS tool
182 chain. Changing the externs to, e.g., uint8_t * does not work
183 with PIC code (generates relocation errors). */
185 base = (uint8_t *)download_start;
186 len = (uint8_t *)download_end - (uint8_t *)download_start;
188 xprintf("PCI download: base %p len %d\n", base, len);
190 fh = cfe_open(tok);
191 if (fh < 0) {
192 xprintf("Could not open device: %s\n", cfe_errortext(fh));
193 return fh;
196 res = cfe_write(fh, base, len);
197 if (res != 0) {
198 xprintf("Could not download device: %s\n", cfe_errortext(res));
201 cfe_close(fh);
203 return res;
205 #endif /* CFG_DOWNLOAD */
210 static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[])
212 int64_t t;
214 t = cfe_ticks;
216 while (!console_status()) {
217 cfe_sleep(CFE_HZ);
218 if (t != cfe_ticks) {
219 xprintf("Time is %lld\n",cfe_ticks);
220 t = cfe_ticks;
224 return 0;