2 * (C) Copyright 2012-2013, Xilinx, Michal Simek
5 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
6 * Keith Outwater, keith_outwater@mvis.com
8 * SPDX-License-Identifier: GPL-2.0+
22 /* Local Static Functions */
23 static int xilinx_validate(xilinx_desc *desc, char *fn);
25 /* ------------------------------------------------------------------------- */
27 int fpga_loadbitstream(int devnum, char *fpgadata, size_t size,
28 bitstream_type bstype)
31 unsigned int swapsize;
33 unsigned char *dataptr;
35 const fpga_desc *desc;
38 dataptr = (unsigned char *)fpgadata;
39 /* Find out fpga_description */
40 desc = fpga_validate(devnum, dataptr, 0, (char *)__func__);
41 /* Assign xilinx device description */
42 xdesc = desc->devdesc;
44 /* skip the first bytes of the bitsteam, their meaning is unknown */
45 length = (*dataptr << 8) + *(dataptr + 1);
49 /* get design name (identifier, length, string) */
50 length = (*dataptr << 8) + *(dataptr + 1);
52 if (*dataptr++ != 0x61) {
53 debug("%s: Design name id not recognized in bitstream\n",
58 length = (*dataptr << 8) + *(dataptr + 1);
60 for (i = 0; i < length; i++)
61 buffer[i] = *dataptr++;
63 printf(" design filename = \"%s\"\n", buffer);
65 /* get part number (identifier, length, string) */
66 if (*dataptr++ != 0x62) {
67 printf("%s: Part number id not recognized in bitstream\n",
72 length = (*dataptr << 8) + *(dataptr + 1);
74 for (i = 0; i < length; i++)
75 buffer[i] = *dataptr++;
78 i = strncmp(buffer, xdesc->name, strlen(xdesc->name));
80 printf("%s: Wrong bitstream ID for this device\n",
82 printf("%s: Bitstream ID %s, current device ID %d/%s\n",
83 __func__, buffer, devnum, xdesc->name);
87 printf("%s: Please fill correct device ID to xilinx_desc\n",
90 printf(" part number = \"%s\"\n", buffer);
92 /* get date (identifier, length, string) */
93 if (*dataptr++ != 0x63) {
94 printf("%s: Date identifier not recognized in bitstream\n",
99 length = (*dataptr << 8) + *(dataptr+1);
101 for (i = 0; i < length; i++)
102 buffer[i] = *dataptr++;
103 printf(" date = \"%s\"\n", buffer);
105 /* get time (identifier, length, string) */
106 if (*dataptr++ != 0x64) {
107 printf("%s: Time identifier not recognized in bitstream\n",
112 length = (*dataptr << 8) + *(dataptr+1);
114 for (i = 0; i < length; i++)
115 buffer[i] = *dataptr++;
116 printf(" time = \"%s\"\n", buffer);
118 /* get fpga data length (identifier, length) */
119 if (*dataptr++ != 0x65) {
120 printf("%s: Data length id not recognized in bitstream\n",
124 swapsize = ((unsigned int) *dataptr << 24) +
125 ((unsigned int) *(dataptr + 1) << 16) +
126 ((unsigned int) *(dataptr + 2) << 8) +
127 ((unsigned int) *(dataptr + 3));
129 printf(" bytes in bitstream = %d\n", swapsize);
131 return fpga_load(devnum, dataptr, swapsize, bstype);
134 int xilinx_load(xilinx_desc *desc, const void *buf, size_t bsize,
135 bitstream_type bstype)
137 if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
138 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
142 return desc->operations->load(desc, buf, bsize, bstype);
145 #if defined(CONFIG_CMD_FPGA_LOADFS)
146 int xilinx_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,
147 fpga_fs_info *fpga_fsinfo)
149 if (!xilinx_validate(desc, (char *)__func__)) {
150 printf("%s: Invalid device descriptor\n", __func__);
154 if (!desc->operations->loadfs)
157 return desc->operations->loadfs(desc, buf, bsize, fpga_fsinfo);
161 int xilinx_dump(xilinx_desc *desc, const void *buf, size_t bsize)
163 if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
164 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
168 return desc->operations->dump(desc, buf, bsize);
171 int xilinx_info(xilinx_desc *desc)
173 int ret_val = FPGA_FAIL;
175 if (xilinx_validate (desc, (char *)__FUNCTION__)) {
176 printf ("Family: \t");
177 switch (desc->family) {
178 case xilinx_spartan2:
179 printf ("Spartan-II\n");
181 case xilinx_spartan3:
182 printf ("Spartan-III\n");
185 printf ("Virtex-II\n");
190 /* Add new family types here */
192 printf ("Unknown family type, %d\n", desc->family);
195 printf ("Interface type:\t");
196 switch (desc->iface) {
198 printf ("Slave Serial\n");
200 case master_serial: /* Not used */
201 printf ("Master Serial\n");
204 printf ("Slave Parallel\n");
206 case jtag_mode: /* Not used */
207 printf ("JTAG Mode\n");
209 case slave_selectmap:
210 printf ("Slave SelectMap Mode\n");
212 case master_selectmap:
213 printf ("Master SelectMap Mode\n");
216 printf("Device configuration interface (Zynq)\n");
218 /* Add new interface types here */
220 printf ("Unsupported interface type, %d\n", desc->iface);
223 printf("Device Size: \t%zd bytes\n"
224 "Cookie: \t0x%x (%d)\n",
225 desc->size, desc->cookie, desc->cookie);
227 printf("Device name: \t%s\n", desc->name);
229 if (desc->iface_fns) {
230 printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
231 desc->operations->info(desc);
233 printf ("No Device Function Table.\n");
235 ret_val = FPGA_SUCCESS;
237 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
243 /* ------------------------------------------------------------------------- */
245 static int xilinx_validate(xilinx_desc *desc, char *fn)
250 if ((desc->family > min_xilinx_type) &&
251 (desc->family < max_xilinx_type)) {
252 if ((desc->iface > min_xilinx_iface_type) &&
253 (desc->iface < max_xilinx_iface_type)) {
257 printf ("%s: NULL part size\n", fn);
259 printf ("%s: Invalid Interface type, %d\n",
262 printf ("%s: Invalid family type, %d\n", fn, desc->family);
264 printf ("%s: NULL descriptor!\n", fn);