3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
4 * Keith Outwater, keith_outwater@mvis.com
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
39 /* Define FPGA_DEBUG to get debug printf's */
41 #define PRINTF(fmt,args...) printf (fmt ,##args)
43 #define PRINTF(fmt,args...)
46 /* Local Static Functions */
47 static int xilinx_validate (Xilinx_desc * desc, char *fn);
49 /* ------------------------------------------------------------------------- */
51 int fpga_loadbitstream(int devnum, char *fpgadata, size_t size)
54 unsigned int swapsize;
56 unsigned char *dataptr;
59 dataptr = (unsigned char *)fpgadata;
61 /* skip the first bytes of the bitsteam, their meaning is unknown */
62 length = (*dataptr << 8) + *(dataptr + 1);
66 /* get design name (identifier, length, string) */
67 length = (*dataptr << 8) + *(dataptr + 1);
69 if (*dataptr++ != 0x61) {
70 debug("%s: Design name id not recognized in bitstream\n",
75 length = (*dataptr << 8) + *(dataptr + 1);
77 for (i = 0; i < length; i++)
78 buffer[i] = *dataptr++;
80 printf(" design filename = \"%s\"\n", buffer);
82 /* get part number (identifier, length, string) */
83 if (*dataptr++ != 0x62) {
84 printf("%s: Part number id not recognized in bitstream\n",
89 length = (*dataptr << 8) + *(dataptr + 1);
91 for (i = 0; i < length; i++)
92 buffer[i] = *dataptr++;
93 printf(" part number = \"%s\"\n", buffer);
95 /* get date (identifier, length, string) */
96 if (*dataptr++ != 0x63) {
97 printf("%s: Date identifier not recognized in bitstream\n",
102 length = (*dataptr << 8) + *(dataptr+1);
104 for (i = 0; i < length; i++)
105 buffer[i] = *dataptr++;
106 printf(" date = \"%s\"\n", buffer);
108 /* get time (identifier, length, string) */
109 if (*dataptr++ != 0x64) {
110 printf("%s: Time identifier not recognized in bitstream\n",
115 length = (*dataptr << 8) + *(dataptr+1);
117 for (i = 0; i < length; i++)
118 buffer[i] = *dataptr++;
119 printf(" time = \"%s\"\n", buffer);
121 /* get fpga data length (identifier, length) */
122 if (*dataptr++ != 0x65) {
123 printf("%s: Data length id not recognized in bitstream\n",
127 swapsize = ((unsigned int) *dataptr << 24) +
128 ((unsigned int) *(dataptr + 1) << 16) +
129 ((unsigned int) *(dataptr + 2) << 8) +
130 ((unsigned int) *(dataptr + 3));
132 printf(" bytes in bitstream = %d\n", swapsize);
134 return fpga_load(devnum, dataptr, swapsize);
137 int xilinx_load(Xilinx_desc *desc, const void *buf, size_t bsize)
139 int ret_val = FPGA_FAIL; /* assume a failure */
141 if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
142 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
144 switch (desc->family) {
145 case Xilinx_Spartan2:
146 #if defined(CONFIG_FPGA_SPARTAN2)
147 PRINTF ("%s: Launching the Spartan-II Loader...\n",
149 ret_val = Spartan2_load (desc, buf, bsize);
151 printf ("%s: No support for Spartan-II devices.\n",
155 case Xilinx_Spartan3:
156 #if defined(CONFIG_FPGA_SPARTAN3)
157 PRINTF ("%s: Launching the Spartan-III Loader...\n",
159 ret_val = Spartan3_load (desc, buf, bsize);
161 printf ("%s: No support for Spartan-III devices.\n",
166 #if defined(CONFIG_FPGA_VIRTEX2)
167 PRINTF ("%s: Launching the Virtex-II Loader...\n",
169 ret_val = Virtex2_load (desc, buf, bsize);
171 printf ("%s: No support for Virtex-II devices.\n",
177 printf ("%s: Unsupported family type, %d\n",
178 __FUNCTION__, desc->family);
184 int xilinx_dump(Xilinx_desc *desc, const void *buf, size_t bsize)
186 int ret_val = FPGA_FAIL; /* assume a failure */
188 if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
189 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
191 switch (desc->family) {
192 case Xilinx_Spartan2:
193 #if defined(CONFIG_FPGA_SPARTAN2)
194 PRINTF ("%s: Launching the Spartan-II Reader...\n",
196 ret_val = Spartan2_dump (desc, buf, bsize);
198 printf ("%s: No support for Spartan-II devices.\n",
202 case Xilinx_Spartan3:
203 #if defined(CONFIG_FPGA_SPARTAN3)
204 PRINTF ("%s: Launching the Spartan-III Reader...\n",
206 ret_val = Spartan3_dump (desc, buf, bsize);
208 printf ("%s: No support for Spartan-III devices.\n",
213 #if defined( CONFIG_FPGA_VIRTEX2)
214 PRINTF ("%s: Launching the Virtex-II Reader...\n",
216 ret_val = Virtex2_dump (desc, buf, bsize);
218 printf ("%s: No support for Virtex-II devices.\n",
224 printf ("%s: Unsupported family type, %d\n",
225 __FUNCTION__, desc->family);
231 int xilinx_info (Xilinx_desc * desc)
233 int ret_val = FPGA_FAIL;
235 if (xilinx_validate (desc, (char *)__FUNCTION__)) {
236 printf ("Family: \t");
237 switch (desc->family) {
238 case Xilinx_Spartan2:
239 printf ("Spartan-II\n");
241 case Xilinx_Spartan3:
242 printf ("Spartan-III\n");
245 printf ("Virtex-II\n");
247 /* Add new family types here */
249 printf ("Unknown family type, %d\n", desc->family);
252 printf ("Interface type:\t");
253 switch (desc->iface) {
255 printf ("Slave Serial\n");
257 case master_serial: /* Not used */
258 printf ("Master Serial\n");
261 printf ("Slave Parallel\n");
263 case jtag_mode: /* Not used */
264 printf ("JTAG Mode\n");
266 case slave_selectmap:
267 printf ("Slave SelectMap Mode\n");
269 case master_selectmap:
270 printf ("Master SelectMap Mode\n");
272 /* Add new interface types here */
274 printf ("Unsupported interface type, %d\n", desc->iface);
277 printf ("Device Size: \t%d bytes\n"
278 "Cookie: \t0x%x (%d)\n",
279 desc->size, desc->cookie, desc->cookie);
281 if (desc->iface_fns) {
282 printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
283 switch (desc->family) {
284 case Xilinx_Spartan2:
285 #if defined(CONFIG_FPGA_SPARTAN2)
286 Spartan2_info (desc);
289 printf ("%s: No support for Spartan-II devices.\n",
293 case Xilinx_Spartan3:
294 #if defined(CONFIG_FPGA_SPARTAN3)
295 Spartan3_info (desc);
298 printf ("%s: No support for Spartan-III devices.\n",
303 #if defined(CONFIG_FPGA_VIRTEX2)
307 printf ("%s: No support for Virtex-II devices.\n",
311 /* Add new family types here */
313 /* we don't need a message here - we give one up above */
317 printf ("No Device Function Table.\n");
319 ret_val = FPGA_SUCCESS;
321 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
327 /* ------------------------------------------------------------------------- */
329 static int xilinx_validate (Xilinx_desc * desc, char *fn)
334 if ((desc->family > min_xilinx_type) &&
335 (desc->family < max_xilinx_type)) {
336 if ((desc->iface > min_xilinx_iface_type) &&
337 (desc->iface < max_xilinx_iface_type)) {
341 printf ("%s: NULL part size\n", fn);
343 printf ("%s: Invalid Interface type, %d\n",
346 printf ("%s: Invalid family type, %d\n", fn, desc->family);
348 printf ("%s: NULL descriptor!\n", fn);