blob: 8e180da6575d7fabfddfbcf59f473de11780b970 [file] [log] [blame]
wdenk4a9cbbe2002-08-27 09:48:53 +00001/*
2 * (C) Copyright 2000, 2001
3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 */
24
25/*
26 * FPGA support
27 */
28#include <common.h>
29#include <command.h>
wdenk4a9cbbe2002-08-27 09:48:53 +000030#if (CONFIG_COMMANDS & CFG_CMD_NET)
31#include <net.h>
32#endif
wdenk8bde7f72003-06-27 21:31:46 +000033#include <fpga.h>
wdenk4a9cbbe2002-08-27 09:48:53 +000034
35#if 0
36#define FPGA_DEBUG
37#endif
38
39#ifdef FPGA_DEBUG
40#define PRINTF(fmt,args...) printf (fmt ,##args)
41#else
42#define PRINTF(fmt,args...)
43#endif
44
45#if defined (CONFIG_FPGA) && ( CONFIG_COMMANDS & CFG_CMD_FPGA )
46
47/* Local functions */
48static void fpga_usage ( cmd_tbl_t *cmdtp );
49static int fpga_get_op( char *opstr );
50
51/* Local defines */
52#define FPGA_NONE -1
53#define FPGA_INFO 0
54#define FPGA_LOAD 1
55#define FPGA_DUMP 3
56
57/* ------------------------------------------------------------------------- */
58/* command form:
59 * fpga <op> <device number> <data addr> <datasize>
60 * where op is 'load', 'dump', or 'info'
61 * If there is no device number field, the fpga environment variable is used.
62 * If there is no data addr field, the fpgadata environment variable is used.
63 * The info command requires no data address field.
64 */
65int
66do_fpga (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
67{
68 int op, dev = FPGA_INVALID_DEVICE;
69 size_t data_size = 0;
70 void *fpga_data = NULL;
71 char *devstr = getenv("fpga");
72 char *datastr = getenv("fpgadata");
73
74 if ( devstr ) dev = (int)simple_strtoul( devstr, NULL, 16 );
75 if ( datastr ) fpga_data = (void *)simple_strtoul( datastr, NULL, 16 );
76
77 switch ( argc )
78 {
79 case 5: /* fpga <op> <dev> <data> <datasize> */
80 data_size = simple_strtoul( argv[4], NULL, 16 );
81 case 4: /* fpga <op> <dev> <data> */
82 fpga_data = (void *)simple_strtoul( argv[3], NULL, 16 );
83 PRINTF(__FUNCTION__": fpga_data = 0x%x\n", (uint)fpga_data );
84 case 3: /* fpga <op> <dev | data addr> */
85 dev = (int)simple_strtoul( argv[2], NULL, 16 );
86 PRINTF(__FUNCTION__": device = %d\n", dev );
87 /* FIXME - this is a really weak test */
88 if (( argc == 3 ) && ( dev > fpga_count() )) { /* must be buffer ptr */
89 PRINTF(__FUNCTION__": Assuming buffer pointer in arg 3\n");
90 fpga_data = (void *)dev;
91 PRINTF(__FUNCTION__": fpga_data = 0x%x\n", (uint)fpga_data );
92 dev = FPGA_INVALID_DEVICE; /* reset device num */
93 }
94 case 2: /* fpga <op> */
95 op = (int)fpga_get_op( argv[1] );
96 break;
97 default:
98 PRINTF(__FUNCTION__": Too many or too few args (%d)\n", argc );
99 op = FPGA_NONE; /* force usage display */
100 break;
101 }
102
103 switch ( op ) {
104 case FPGA_NONE:
105 fpga_usage( cmdtp );
106 break;
107
108 case FPGA_INFO:
109 fpga_info( dev );
110 break;
111
112 case FPGA_LOAD:
113 fpga_load( dev, fpga_data, data_size );
114 break;
115
116 case FPGA_DUMP:
117 fpga_dump( dev, fpga_data, data_size );
118 break;
119
120 default:
121 printf( "Unknown operation.\n" );
122 fpga_usage( cmdtp );
123 break;
124 }
125 return 0;
126}
127
128static void fpga_usage ( cmd_tbl_t *cmdtp )
129{
130 printf( "Usage:\n%s\n", cmdtp->usage );
131}
132
133/*
134 * Map op to supported operations. We don't use a table since we
135 * would just have to relocate it from flash anyway.
136 */
137static int fpga_get_op( char *opstr )
138{
139 int op = FPGA_NONE;
140
141 if (!strcmp ("info", opstr)) {
142 op = FPGA_INFO;
143 }
144 else if (!strcmp ("load", opstr)) {
145 op = FPGA_LOAD;
146 }
147 else if (!strcmp ("dump", opstr)) {
148 op = FPGA_DUMP;
149 }
150
151 if ( op == FPGA_NONE ) {
152 printf ("Unknown fpga operation \"%s\"\n", opstr);
153 }
154 return op;
155}
156
wdenk0d498392003-07-01 21:06:45 +0000157U_BOOT_CMD(
158 fpga, 6, 1, do_fpga,
wdenk8bde7f72003-06-27 21:31:46 +0000159 "fpga - loadable FPGA image support\n",
160 "fpga [operation type] [device number] [image address] [image size]\n"
161 "fpga operations:\n"
162 "\tinfo\tlist known device information.\n"
163 "\tload\tLoad device from memory buffer.\n"
164 "\tdump\tLoad device to memory buffer.\n"
165);
wdenk4a9cbbe2002-08-27 09:48:53 +0000166#endif /* CONFIG_FPGA && CONFIG_COMMANDS & CFG_CMD_FPGA */