blob: f8ae52a66e5078bc025144db39c6be8ab38165fd [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>
wdenk57b2d802003-06-27 21:31:46 +000030#include <cmd_bsp.h>
wdenk4a9cbbe2002-08-27 09:48:53 +000031#if (CONFIG_COMMANDS & CFG_CMD_NET)
32#include <net.h>
33#endif
wdenk57b2d802003-06-27 21:31:46 +000034#include <fpga.h>
wdenk4a9cbbe2002-08-27 09:48:53 +000035
36#if 0
37#define FPGA_DEBUG
38#endif
39
40#ifdef FPGA_DEBUG
41#define PRINTF(fmt,args...) printf (fmt ,##args)
42#else
43#define PRINTF(fmt,args...)
44#endif
45
46#if defined (CONFIG_FPGA) && ( CONFIG_COMMANDS & CFG_CMD_FPGA )
47
48/* Local functions */
49static void fpga_usage ( cmd_tbl_t *cmdtp );
50static int fpga_get_op( char *opstr );
51
52/* Local defines */
53#define FPGA_NONE -1
54#define FPGA_INFO 0
55#define FPGA_LOAD 1
56#define FPGA_DUMP 3
57
58/* ------------------------------------------------------------------------- */
59/* command form:
60 * fpga <op> <device number> <data addr> <datasize>
61 * where op is 'load', 'dump', or 'info'
62 * If there is no device number field, the fpga environment variable is used.
63 * If there is no data addr field, the fpgadata environment variable is used.
64 * The info command requires no data address field.
65 */
66int
67do_fpga (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
68{
69 int op, dev = FPGA_INVALID_DEVICE;
70 size_t data_size = 0;
71 void *fpga_data = NULL;
72 char *devstr = getenv("fpga");
73 char *datastr = getenv("fpgadata");
74
75 if ( devstr ) dev = (int)simple_strtoul( devstr, NULL, 16 );
76 if ( datastr ) fpga_data = (void *)simple_strtoul( datastr, NULL, 16 );
77
78 switch ( argc )
79 {
80 case 5: /* fpga <op> <dev> <data> <datasize> */
81 data_size = simple_strtoul( argv[4], NULL, 16 );
82 case 4: /* fpga <op> <dev> <data> */
83 fpga_data = (void *)simple_strtoul( argv[3], NULL, 16 );
84 PRINTF(__FUNCTION__": fpga_data = 0x%x\n", (uint)fpga_data );
85 case 3: /* fpga <op> <dev | data addr> */
86 dev = (int)simple_strtoul( argv[2], NULL, 16 );
87 PRINTF(__FUNCTION__": device = %d\n", dev );
88 /* FIXME - this is a really weak test */
89 if (( argc == 3 ) && ( dev > fpga_count() )) { /* must be buffer ptr */
90 PRINTF(__FUNCTION__": Assuming buffer pointer in arg 3\n");
91 fpga_data = (void *)dev;
92 PRINTF(__FUNCTION__": fpga_data = 0x%x\n", (uint)fpga_data );
93 dev = FPGA_INVALID_DEVICE; /* reset device num */
94 }
95 case 2: /* fpga <op> */
96 op = (int)fpga_get_op( argv[1] );
97 break;
98 default:
99 PRINTF(__FUNCTION__": Too many or too few args (%d)\n", argc );
100 op = FPGA_NONE; /* force usage display */
101 break;
102 }
103
104 switch ( op ) {
105 case FPGA_NONE:
106 fpga_usage( cmdtp );
107 break;
108
109 case FPGA_INFO:
110 fpga_info( dev );
111 break;
112
113 case FPGA_LOAD:
114 fpga_load( dev, fpga_data, data_size );
115 break;
116
117 case FPGA_DUMP:
118 fpga_dump( dev, fpga_data, data_size );
119 break;
120
121 default:
122 printf( "Unknown operation.\n" );
123 fpga_usage( cmdtp );
124 break;
125 }
126 return 0;
127}
128
129static void fpga_usage ( cmd_tbl_t *cmdtp )
130{
131 printf( "Usage:\n%s\n", cmdtp->usage );
132}
133
134/*
135 * Map op to supported operations. We don't use a table since we
136 * would just have to relocate it from flash anyway.
137 */
138static int fpga_get_op( char *opstr )
139{
140 int op = FPGA_NONE;
141
142 if (!strcmp ("info", opstr)) {
143 op = FPGA_INFO;
144 }
145 else if (!strcmp ("load", opstr)) {
146 op = FPGA_LOAD;
147 }
148 else if (!strcmp ("dump", opstr)) {
149 op = FPGA_DUMP;
150 }
151
152 if ( op == FPGA_NONE ) {
153 printf ("Unknown fpga operation \"%s\"\n", opstr);
154 }
155 return op;
156}
157
wdenk57b2d802003-06-27 21:31:46 +0000158cmd_tbl_t U_BOOT_CMD(FPGA) = MK_CMD_ENTRY(
159 "fpga", 6, 1, do_fpga,
160 "fpga - loadable FPGA image support\n",
161 "fpga [operation type] [device number] [image address] [image size]\n"
162 "fpga operations:\n"
163 "\tinfo\tlist known device information.\n"
164 "\tload\tLoad device from memory buffer.\n"
165 "\tdump\tLoad device to memory buffer.\n"
166);
wdenk4a9cbbe2002-08-27 09:48:53 +0000167#endif /* CONFIG_FPGA && CONFIG_COMMANDS & CFG_CMD_FPGA */