• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/cfe/cfe/arch/mips/cpu/sb1250/src/
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    *********************************************************************
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
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"
54
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"
61
62#include "cfe_error.h"
63
64#include "env_subr.h"
65#include "ui_command.h"
66#include "cfe.h"
67
68#include "bsp_config.h"
69
70#include "cfe_mem.h"
71
72int ui_init_testcmds(void);
73static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[]);
74#if CFG_DOWNLOAD
75static int ui_cmd_config1250(ui_cmdline_t *cmd,int argc,char *argv[]);
76#endif
77
78int ui_init_testcmds(void)
79{
80
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",
94	       ""
95	);
96#endif
97
98    return 0;
99}
100
101
102
103
104#if CFG_DOWNLOAD
105
106#include "net_ebuf.h"
107#include "net_api.h"
108#include "addrspace.h"
109#include "cfe_loader.h"
110extern cfe_loadargs_t cfe_loadargs;
111
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)
115
116/* Base and bound of compiled-in downloadable image */
117extern void download_start(void), download_end(void);
118
119static int ui_cmd_config1250(ui_cmdline_t *cmd,int argc,char *argv[])
120{
121    char *tok;
122    int fh;
123    uint8_t *base;
124    int len;
125    int res;
126
127    tok = cmd_getarg(cmd, 0);
128    if (!tok) {
129	return ui_showusage(cmd);
130	}
131
132    if (argc > 1) {
133	char *fname;
134	cfe_loadargs_t *la = &cfe_loadargs;
135	int res;
136
137	fname = cmd_getarg(cmd, 1);
138	if (!fname) {
139	    return ui_showusage(cmd);
140	    }
141
142	/* Get the file using tftp and read it into a known location. */
143
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.
150	 */
151
152	/* Fill out the loadargs */
153
154	la->la_flags = LOADFLG_NOISY;
155
156	la->la_device = (char *) net_getparam(NET_DEVNAME);
157	la->la_filesys = "tftp";
158	la->la_filename = fname;
159
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;
164
165	la->la_options = NULL;
166
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);
169
170	res = cfe_load_program("raw", la);
171	if (res < 0) {
172	    xprintf("Could not load %s\n", fname);
173	    return res;
174	    }
175
176	base = (uint8_t *)(la->la_address);
177	len = res;
178	}
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). */
184
185	base = (uint8_t *)download_start;
186	len  = (uint8_t *)download_end - (uint8_t *)download_start;
187	}
188    xprintf("PCI download: base %p len %d\n", base, len);
189
190    fh = cfe_open(tok);
191    if (fh < 0) {
192	xprintf("Could not open device: %s\n", cfe_errortext(fh));
193	return fh;
194	}
195
196    res = cfe_write(fh, base, len);
197    if (res != 0) {
198	xprintf("Could not download device: %s\n", cfe_errortext(res));
199	}
200
201    cfe_close(fh);
202
203    return res;
204}
205#endif /* CFG_DOWNLOAD */
206
207
208
209
210static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[])
211{
212    int64_t t;
213
214    t = cfe_ticks;
215
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;
221	    }
222	}
223
224    return 0;
225}
226