wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 1 | /* |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 2 | * (C) Copyright 2012-2013, Xilinx, Michal Simek |
| 3 | * |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 4 | * (C) Copyright 2002 |
| 5 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
| 6 | * Keith Outwater, keith_outwater@mvis.com |
| 7 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * Xilinx FPGA support |
| 13 | */ |
| 14 | |
| 15 | #include <common.h> |
Michal Simek | 6631db4 | 2013-04-26 15:04:48 +0200 | [diff] [blame] | 16 | #include <fpga.h> |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 17 | #include <virtex2.h> |
| 18 | #include <spartan2.h> |
Wolfgang Denk | 875c789 | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 19 | #include <spartan3.h> |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 20 | #include <zynqpl.h> |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 21 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 22 | /* Local Static Functions */ |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 23 | static int xilinx_validate(xilinx_desc *desc, char *fn); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 24 | |
| 25 | /* ------------------------------------------------------------------------- */ |
| 26 | |
Michal Simek | 7a78bd2 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 27 | int fpga_loadbitstream(int devnum, char *fpgadata, size_t size, |
| 28 | bitstream_type bstype) |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 29 | { |
| 30 | unsigned int length; |
| 31 | unsigned int swapsize; |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 32 | unsigned char *dataptr; |
| 33 | unsigned int i; |
Michal Simek | 6631db4 | 2013-04-26 15:04:48 +0200 | [diff] [blame] | 34 | const fpga_desc *desc; |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 35 | xilinx_desc *xdesc; |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 36 | |
| 37 | dataptr = (unsigned char *)fpgadata; |
Michal Simek | 6631db4 | 2013-04-26 15:04:48 +0200 | [diff] [blame] | 38 | /* Find out fpga_description */ |
| 39 | desc = fpga_validate(devnum, dataptr, 0, (char *)__func__); |
| 40 | /* Assign xilinx device description */ |
| 41 | xdesc = desc->devdesc; |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 42 | |
| 43 | /* skip the first bytes of the bitsteam, their meaning is unknown */ |
| 44 | length = (*dataptr << 8) + *(dataptr + 1); |
| 45 | dataptr += 2; |
| 46 | dataptr += length; |
| 47 | |
| 48 | /* get design name (identifier, length, string) */ |
| 49 | length = (*dataptr << 8) + *(dataptr + 1); |
| 50 | dataptr += 2; |
| 51 | if (*dataptr++ != 0x61) { |
| 52 | debug("%s: Design name id not recognized in bitstream\n", |
| 53 | __func__); |
| 54 | return FPGA_FAIL; |
| 55 | } |
| 56 | |
| 57 | length = (*dataptr << 8) + *(dataptr + 1); |
| 58 | dataptr += 2; |
Siva Durga Prasad Paladugu | d863909 | 2017-03-02 18:50:11 +0530 | [diff] [blame] | 59 | printf(" design filename = \"%s\"\n", dataptr); |
| 60 | dataptr += length; |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 61 | |
| 62 | /* get part number (identifier, length, string) */ |
| 63 | if (*dataptr++ != 0x62) { |
| 64 | printf("%s: Part number id not recognized in bitstream\n", |
| 65 | __func__); |
| 66 | return FPGA_FAIL; |
| 67 | } |
| 68 | |
| 69 | length = (*dataptr << 8) + *(dataptr + 1); |
| 70 | dataptr += 2; |
Michal Simek | 6631db4 | 2013-04-26 15:04:48 +0200 | [diff] [blame] | 71 | |
| 72 | if (xdesc->name) { |
Siva Durga Prasad Paladugu | d863909 | 2017-03-02 18:50:11 +0530 | [diff] [blame] | 73 | i = (ulong)strstr((char *)dataptr, xdesc->name); |
Siva Durga Prasad Paladugu | f721326 | 2016-01-11 12:30:41 +0530 | [diff] [blame] | 74 | if (!i) { |
Michal Simek | 6631db4 | 2013-04-26 15:04:48 +0200 | [diff] [blame] | 75 | printf("%s: Wrong bitstream ID for this device\n", |
| 76 | __func__); |
| 77 | printf("%s: Bitstream ID %s, current device ID %d/%s\n", |
Siva Durga Prasad Paladugu | d863909 | 2017-03-02 18:50:11 +0530 | [diff] [blame] | 78 | __func__, dataptr, devnum, xdesc->name); |
Michal Simek | 6631db4 | 2013-04-26 15:04:48 +0200 | [diff] [blame] | 79 | return FPGA_FAIL; |
| 80 | } |
| 81 | } else { |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 82 | printf("%s: Please fill correct device ID to xilinx_desc\n", |
Michal Simek | 6631db4 | 2013-04-26 15:04:48 +0200 | [diff] [blame] | 83 | __func__); |
| 84 | } |
Siva Durga Prasad Paladugu | d863909 | 2017-03-02 18:50:11 +0530 | [diff] [blame] | 85 | printf(" part number = \"%s\"\n", dataptr); |
| 86 | dataptr += length; |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 87 | |
| 88 | /* get date (identifier, length, string) */ |
| 89 | if (*dataptr++ != 0x63) { |
| 90 | printf("%s: Date identifier not recognized in bitstream\n", |
| 91 | __func__); |
| 92 | return FPGA_FAIL; |
| 93 | } |
| 94 | |
| 95 | length = (*dataptr << 8) + *(dataptr+1); |
| 96 | dataptr += 2; |
Siva Durga Prasad Paladugu | d863909 | 2017-03-02 18:50:11 +0530 | [diff] [blame] | 97 | printf(" date = \"%s\"\n", dataptr); |
| 98 | dataptr += length; |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 99 | |
| 100 | /* get time (identifier, length, string) */ |
| 101 | if (*dataptr++ != 0x64) { |
| 102 | printf("%s: Time identifier not recognized in bitstream\n", |
| 103 | __func__); |
| 104 | return FPGA_FAIL; |
| 105 | } |
| 106 | |
| 107 | length = (*dataptr << 8) + *(dataptr+1); |
| 108 | dataptr += 2; |
Siva Durga Prasad Paladugu | d863909 | 2017-03-02 18:50:11 +0530 | [diff] [blame] | 109 | printf(" time = \"%s\"\n", dataptr); |
| 110 | dataptr += length; |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 111 | |
| 112 | /* get fpga data length (identifier, length) */ |
| 113 | if (*dataptr++ != 0x65) { |
| 114 | printf("%s: Data length id not recognized in bitstream\n", |
| 115 | __func__); |
| 116 | return FPGA_FAIL; |
| 117 | } |
| 118 | swapsize = ((unsigned int) *dataptr << 24) + |
| 119 | ((unsigned int) *(dataptr + 1) << 16) + |
| 120 | ((unsigned int) *(dataptr + 2) << 8) + |
| 121 | ((unsigned int) *(dataptr + 3)); |
| 122 | dataptr += 4; |
| 123 | printf(" bytes in bitstream = %d\n", swapsize); |
| 124 | |
Michal Simek | 7a78bd2 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 125 | return fpga_load(devnum, dataptr, swapsize, bstype); |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Michal Simek | 7a78bd2 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 128 | int xilinx_load(xilinx_desc *desc, const void *buf, size_t bsize, |
| 129 | bitstream_type bstype) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 130 | { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 131 | if (!xilinx_validate (desc, (char *)__FUNCTION__)) { |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 132 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
Michal Simek | 14cfc4f | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 133 | return FPGA_FAIL; |
| 134 | } |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 135 | |
Michal Simek | 6cd68c8 | 2014-07-16 10:31:21 +0200 | [diff] [blame] | 136 | if (!desc->operations || !desc->operations->load) { |
| 137 | printf("%s: Missing load operation\n", __func__); |
| 138 | return FPGA_FAIL; |
| 139 | } |
| 140 | |
Michal Simek | 7a78bd2 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 141 | return desc->operations->load(desc, buf, bsize, bstype); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Siva Durga Prasad Paladugu | 1a89766 | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 144 | #if defined(CONFIG_CMD_FPGA_LOADFS) |
| 145 | int xilinx_loadfs(xilinx_desc *desc, const void *buf, size_t bsize, |
| 146 | fpga_fs_info *fpga_fsinfo) |
| 147 | { |
| 148 | if (!xilinx_validate(desc, (char *)__func__)) { |
| 149 | printf("%s: Invalid device descriptor\n", __func__); |
| 150 | return FPGA_FAIL; |
| 151 | } |
| 152 | |
Michal Simek | 6cd68c8 | 2014-07-16 10:31:21 +0200 | [diff] [blame] | 153 | if (!desc->operations || !desc->operations->loadfs) { |
| 154 | printf("%s: Missing loadfs operation\n", __func__); |
Siva Durga Prasad Paladugu | 1a89766 | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 155 | return FPGA_FAIL; |
Michal Simek | 6cd68c8 | 2014-07-16 10:31:21 +0200 | [diff] [blame] | 156 | } |
Siva Durga Prasad Paladugu | 1a89766 | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 157 | |
| 158 | return desc->operations->loadfs(desc, buf, bsize, fpga_fsinfo); |
| 159 | } |
| 160 | #endif |
| 161 | |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 162 | int xilinx_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 163 | { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 164 | if (!xilinx_validate (desc, (char *)__FUNCTION__)) { |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 165 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
Michal Simek | 14cfc4f | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 166 | return FPGA_FAIL; |
| 167 | } |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 168 | |
Michal Simek | 6cd68c8 | 2014-07-16 10:31:21 +0200 | [diff] [blame] | 169 | if (!desc->operations || !desc->operations->dump) { |
| 170 | printf("%s: Missing dump operation\n", __func__); |
| 171 | return FPGA_FAIL; |
| 172 | } |
| 173 | |
Michal Simek | 14cfc4f | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 174 | return desc->operations->dump(desc, buf, bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 177 | int xilinx_info(xilinx_desc *desc) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 178 | { |
| 179 | int ret_val = FPGA_FAIL; |
| 180 | |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 181 | if (xilinx_validate (desc, (char *)__FUNCTION__)) { |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 182 | printf ("Family: \t"); |
| 183 | switch (desc->family) { |
Michal Simek | b625b9a | 2014-03-13 11:23:43 +0100 | [diff] [blame] | 184 | case xilinx_spartan2: |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 185 | printf ("Spartan-II\n"); |
| 186 | break; |
Michal Simek | 2a6e386 | 2014-03-13 11:28:42 +0100 | [diff] [blame] | 187 | case xilinx_spartan3: |
Wolfgang Denk | 875c789 | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 188 | printf ("Spartan-III\n"); |
| 189 | break; |
Michal Simek | d9071ce | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 190 | case xilinx_virtex2: |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 191 | printf ("Virtex-II\n"); |
| 192 | break; |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 193 | case xilinx_zynq: |
| 194 | printf("Zynq PL\n"); |
| 195 | break; |
Siva Durga Prasad Paladugu | 6b24501 | 2016-01-13 16:25:37 +0530 | [diff] [blame] | 196 | case xilinx_zynqmp: |
| 197 | printf("ZynqMP PL\n"); |
| 198 | break; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 199 | /* Add new family types here */ |
| 200 | default: |
| 201 | printf ("Unknown family type, %d\n", desc->family); |
| 202 | } |
| 203 | |
| 204 | printf ("Interface type:\t"); |
| 205 | switch (desc->iface) { |
| 206 | case slave_serial: |
| 207 | printf ("Slave Serial\n"); |
| 208 | break; |
| 209 | case master_serial: /* Not used */ |
| 210 | printf ("Master Serial\n"); |
| 211 | break; |
| 212 | case slave_parallel: |
| 213 | printf ("Slave Parallel\n"); |
| 214 | break; |
| 215 | case jtag_mode: /* Not used */ |
| 216 | printf ("JTAG Mode\n"); |
| 217 | break; |
| 218 | case slave_selectmap: |
| 219 | printf ("Slave SelectMap Mode\n"); |
| 220 | break; |
| 221 | case master_selectmap: |
| 222 | printf ("Master SelectMap Mode\n"); |
| 223 | break; |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 224 | case devcfg: |
| 225 | printf("Device configuration interface (Zynq)\n"); |
| 226 | break; |
Siva Durga Prasad Paladugu | 6b24501 | 2016-01-13 16:25:37 +0530 | [diff] [blame] | 227 | case csu_dma: |
| 228 | printf("csu_dma configuration interface (ZynqMP)\n"); |
| 229 | break; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 230 | /* Add new interface types here */ |
| 231 | default: |
| 232 | printf ("Unsupported interface type, %d\n", desc->iface); |
| 233 | } |
| 234 | |
Simon Glass | ddc9437 | 2014-06-07 22:07:58 -0600 | [diff] [blame] | 235 | printf("Device Size: \t%zd bytes\n" |
| 236 | "Cookie: \t0x%x (%d)\n", |
| 237 | desc->size, desc->cookie, desc->cookie); |
Michal Simek | 6631db4 | 2013-04-26 15:04:48 +0200 | [diff] [blame] | 238 | if (desc->name) |
| 239 | printf("Device name: \t%s\n", desc->name); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 240 | |
Michal Simek | e136eae | 2014-07-16 10:36:42 +0200 | [diff] [blame] | 241 | if (desc->iface_fns) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 242 | printf ("Device Function Table @ 0x%p\n", desc->iface_fns); |
Michal Simek | e136eae | 2014-07-16 10:36:42 +0200 | [diff] [blame] | 243 | else |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 244 | printf ("No Device Function Table.\n"); |
| 245 | |
Michal Simek | e136eae | 2014-07-16 10:36:42 +0200 | [diff] [blame] | 246 | if (desc->operations && desc->operations->info) |
| 247 | desc->operations->info(desc); |
| 248 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 249 | ret_val = FPGA_SUCCESS; |
| 250 | } else { |
| 251 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 252 | } |
| 253 | |
| 254 | return ret_val; |
| 255 | } |
| 256 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 257 | /* ------------------------------------------------------------------------- */ |
| 258 | |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 259 | static int xilinx_validate(xilinx_desc *desc, char *fn) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 260 | { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 261 | int ret_val = false; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 262 | |
| 263 | if (desc) { |
| 264 | if ((desc->family > min_xilinx_type) && |
| 265 | (desc->family < max_xilinx_type)) { |
| 266 | if ((desc->iface > min_xilinx_iface_type) && |
| 267 | (desc->iface < max_xilinx_iface_type)) { |
| 268 | if (desc->size) { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 269 | ret_val = true; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 270 | } else |
| 271 | printf ("%s: NULL part size\n", fn); |
| 272 | } else |
| 273 | printf ("%s: Invalid Interface type, %d\n", |
| 274 | fn, desc->iface); |
| 275 | } else |
| 276 | printf ("%s: Invalid family type, %d\n", fn, desc->family); |
| 277 | } else |
| 278 | printf ("%s: NULL descriptor!\n", fn); |
| 279 | |
| 280 | return ret_val; |
| 281 | } |