1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2012-2013, Xilinx, Michal Simek
6 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
7 * Keith Outwater, keith_outwater@mvis.com
21 /* Local Static Functions */
22 static int xilinx_validate(xilinx_desc *desc, char *fn);
24 /* ------------------------------------------------------------------------- */
26 int fpga_is_partial_data(int devnum, size_t img_len)
28 const fpga_desc * const desc = fpga_get_desc(devnum);
29 xilinx_desc *desc_xilinx = desc->devdesc;
31 /* Check datasize against FPGA size */
32 if (img_len >= desc_xilinx->size)
35 /* datasize is smaller, must be partial data */
39 int fpga_loadbitstream(int devnum, char *fpgadata, size_t size,
40 bitstream_type bstype)
43 unsigned int swapsize;
44 unsigned char *dataptr;
46 const fpga_desc *desc;
49 dataptr = (unsigned char *)fpgadata;
50 /* Find out fpga_description */
51 desc = fpga_validate(devnum, dataptr, 0, (char *)__func__);
52 /* Assign xilinx device description */
53 xdesc = desc->devdesc;
55 /* skip the first bytes of the bitsteam, their meaning is unknown */
56 length = (*dataptr << 8) + *(dataptr + 1);
60 /* get design name (identifier, length, string) */
61 length = (*dataptr << 8) + *(dataptr + 1);
63 if (*dataptr++ != 0x61) {
64 debug("%s: Design name id not recognized in bitstream\n",
69 length = (*dataptr << 8) + *(dataptr + 1);
71 printf(" design filename = \"%s\"\n", dataptr);
74 /* get part number (identifier, length, string) */
75 if (*dataptr++ != 0x62) {
76 printf("%s: Part number id not recognized in bitstream\n",
81 length = (*dataptr << 8) + *(dataptr + 1);
85 i = (ulong)strstr((char *)dataptr, xdesc->name);
87 printf("%s: Wrong bitstream ID for this device\n",
89 printf("%s: Bitstream ID %s, current device ID %d/%s\n",
90 __func__, dataptr, devnum, xdesc->name);
94 printf("%s: Please fill correct device ID to xilinx_desc\n",
97 printf(" part number = \"%s\"\n", dataptr);
100 /* get date (identifier, length, string) */
101 if (*dataptr++ != 0x63) {
102 printf("%s: Date identifier not recognized in bitstream\n",
107 length = (*dataptr << 8) + *(dataptr+1);
109 printf(" date = \"%s\"\n", dataptr);
112 /* get time (identifier, length, string) */
113 if (*dataptr++ != 0x64) {
114 printf("%s: Time identifier not recognized in bitstream\n",
119 length = (*dataptr << 8) + *(dataptr+1);
121 printf(" time = \"%s\"\n", dataptr);
124 /* get fpga data length (identifier, length) */
125 if (*dataptr++ != 0x65) {
126 printf("%s: Data length id not recognized in bitstream\n",
130 swapsize = ((unsigned int) *dataptr << 24) +
131 ((unsigned int) *(dataptr + 1) << 16) +
132 ((unsigned int) *(dataptr + 2) << 8) +
133 ((unsigned int) *(dataptr + 3));
135 printf(" bytes in bitstream = %d\n", swapsize);
137 return fpga_load(devnum, dataptr, swapsize, bstype);
140 int xilinx_load(xilinx_desc *desc, const void *buf, size_t bsize,
141 bitstream_type bstype)
143 if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
144 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
148 if (!desc->operations || !desc->operations->load) {
149 printf("%s: Missing load operation\n", __func__);
153 return desc->operations->load(desc, buf, bsize, bstype);
156 #if defined(CONFIG_CMD_FPGA_LOADFS)
157 int xilinx_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,
158 fpga_fs_info *fpga_fsinfo)
160 if (!xilinx_validate(desc, (char *)__func__)) {
161 printf("%s: Invalid device descriptor\n", __func__);
165 if (!desc->operations || !desc->operations->loadfs) {
166 printf("%s: Missing loadfs operation\n", __func__);
170 return desc->operations->loadfs(desc, buf, bsize, fpga_fsinfo);
174 #if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
175 int xilinx_loads(xilinx_desc *desc, const void *buf, size_t bsize,
176 struct fpga_secure_info *fpga_sec_info)
178 if (!xilinx_validate(desc, (char *)__func__)) {
179 printf("%s: Invalid device descriptor\n", __func__);
183 if (!desc->operations || !desc->operations->loads) {
184 printf("%s: Missing loads operation\n", __func__);
188 return desc->operations->loads(desc, buf, bsize, fpga_sec_info);
192 int xilinx_dump(xilinx_desc *desc, const void *buf, size_t bsize)
194 if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
195 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
199 if (!desc->operations || !desc->operations->dump) {
200 printf("%s: Missing dump operation\n", __func__);
204 return desc->operations->dump(desc, buf, bsize);
207 int xilinx_info(xilinx_desc *desc)
209 int ret_val = FPGA_FAIL;
211 if (xilinx_validate (desc, (char *)__FUNCTION__)) {
212 printf ("Family: \t");
213 switch (desc->family) {
214 case xilinx_spartan2:
215 printf ("Spartan-II\n");
217 case xilinx_spartan3:
218 printf ("Spartan-III\n");
221 printf ("Virtex-II\n");
227 printf("ZynqMP PL\n");
230 printf("Versal PL\n");
232 /* Add new family types here */
234 printf ("Unknown family type, %d\n", desc->family);
237 printf ("Interface type:\t");
238 switch (desc->iface) {
240 printf ("Slave Serial\n");
242 case master_serial: /* Not used */
243 printf ("Master Serial\n");
246 printf ("Slave Parallel\n");
248 case jtag_mode: /* Not used */
249 printf ("JTAG Mode\n");
251 case slave_selectmap:
252 printf ("Slave SelectMap Mode\n");
254 case master_selectmap:
255 printf ("Master SelectMap Mode\n");
258 printf("Device configuration interface (Zynq)\n");
261 printf("csu_dma configuration interface (ZynqMP)\n");
264 printf("CFI configuration interface (Versal)\n");
266 /* Add new interface types here */
268 printf ("Unsupported interface type, %d\n", desc->iface);
271 printf("Device Size: \t%zd bytes\n"
272 "Cookie: \t0x%x (%d)\n",
273 desc->size, desc->cookie, desc->cookie);
275 printf("Device name: \t%s\n", desc->name);
278 printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
280 printf ("No Device Function Table.\n");
282 if (desc->operations && desc->operations->info)
283 desc->operations->info(desc);
285 ret_val = FPGA_SUCCESS;
287 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
293 /* ------------------------------------------------------------------------- */
295 static int xilinx_validate(xilinx_desc *desc, char *fn)
300 if ((desc->family > min_xilinx_type) &&
301 (desc->family < max_xilinx_type)) {
302 if ((desc->iface > min_xilinx_iface_type) &&
303 (desc->iface < max_xilinx_iface_type)) {
307 printf ("%s: NULL part size\n", fn);
309 printf ("%s: Invalid Interface type, %d\n",
312 printf ("%s: Invalid family type, %d\n", fn, desc->family);
314 printf ("%s: NULL descriptor!\n", fn);