1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Test commands File: cfe_tests.c
6 * A temporary sandbox for misc test routines and commands.
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
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"
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"
65 #include "ui_command.h"
68 #include "bsp_config.h"
72 int ui_init_testcmds(void);
73 static int ui_cmd_timertest(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
75 static int ui_cmd_config1250(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
78 int ui_init_testcmds(void)
81 cmd_addcmd("test timer",
88 cmd_addcmd("test bcm1250",
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",
106 #include "net_ebuf.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
[])
127 tok
= cmd_getarg(cmd
, 0);
129 return ui_showusage(cmd
);
134 cfe_loadargs_t
*la
= &cfe_loadargs
;
137 fname
= cmd_getarg(cmd
, 1);
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
);
172 xprintf("Could not load %s\n", fname
);
176 base
= (uint8_t *)(la
->la_address
);
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
);
192 xprintf("Could not open device: %s\n", cfe_errortext(fh
));
196 res
= cfe_write(fh
, base
, len
);
198 xprintf("Could not download device: %s\n", cfe_errortext(res
));
205 #endif /* CFG_DOWNLOAD */
210 static int ui_cmd_timertest(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
216 while (!console_status()) {
218 if (t
!= cfe_ticks
) {
219 xprintf("Time is %lld\n",cfe_ticks
);