2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-08-21 22:08:56 +00:00
|
|
|
/*
|
2013-04-22 13:43:02 +00:00
|
|
|
* (C) Copyright 2012-2013, Xilinx, Michal Simek
|
|
|
|
*
|
2002-08-21 22:08:56 +00:00
|
|
|
* (C) Copyright 2002
|
|
|
|
* Rich Ireland, Enterasys Networks, rireland@enterasys.com.
|
|
|
|
* Keith Outwater, keith_outwater@mvis.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Xilinx FPGA support
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2013-04-26 13:04:48 +00:00
|
|
|
#include <fpga.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2002-08-21 22:08:56 +00:00
|
|
|
#include <virtex2.h>
|
|
|
|
#include <spartan2.h>
|
2005-09-25 14:44:21 +00:00
|
|
|
#include <spartan3.h>
|
2013-04-22 13:43:02 +00:00
|
|
|
#include <zynqpl.h>
|
2002-08-21 22:08:56 +00:00
|
|
|
|
|
|
|
/* Local Static Functions */
|
2014-03-13 11:49:21 +00:00
|
|
|
static int xilinx_validate(xilinx_desc *desc, char *fn);
|
2002-08-21 22:08:56 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2017-11-10 14:17:41 +00:00
|
|
|
int fpga_is_partial_data(int devnum, size_t img_len)
|
|
|
|
{
|
|
|
|
const fpga_desc * const desc = fpga_get_desc(devnum);
|
|
|
|
xilinx_desc *desc_xilinx = desc->devdesc;
|
|
|
|
|
|
|
|
/* Check datasize against FPGA size */
|
|
|
|
if (img_len >= desc_xilinx->size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* datasize is smaller, must be partial data */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-05-02 12:09:30 +00:00
|
|
|
int fpga_loadbitstream(int devnum, char *fpgadata, size_t size,
|
|
|
|
bitstream_type bstype)
|
2013-04-26 11:12:07 +00:00
|
|
|
{
|
|
|
|
unsigned int length;
|
|
|
|
unsigned int swapsize;
|
|
|
|
unsigned char *dataptr;
|
|
|
|
unsigned int i;
|
2013-04-26 13:04:48 +00:00
|
|
|
const fpga_desc *desc;
|
2014-03-13 11:49:21 +00:00
|
|
|
xilinx_desc *xdesc;
|
2013-04-26 11:12:07 +00:00
|
|
|
|
|
|
|
dataptr = (unsigned char *)fpgadata;
|
2013-04-26 13:04:48 +00:00
|
|
|
/* Find out fpga_description */
|
|
|
|
desc = fpga_validate(devnum, dataptr, 0, (char *)__func__);
|
|
|
|
/* Assign xilinx device description */
|
|
|
|
xdesc = desc->devdesc;
|
2013-04-26 11:12:07 +00:00
|
|
|
|
|
|
|
/* skip the first bytes of the bitsteam, their meaning is unknown */
|
|
|
|
length = (*dataptr << 8) + *(dataptr + 1);
|
|
|
|
dataptr += 2;
|
|
|
|
dataptr += length;
|
|
|
|
|
|
|
|
/* get design name (identifier, length, string) */
|
|
|
|
length = (*dataptr << 8) + *(dataptr + 1);
|
|
|
|
dataptr += 2;
|
|
|
|
if (*dataptr++ != 0x61) {
|
|
|
|
debug("%s: Design name id not recognized in bitstream\n",
|
|
|
|
__func__);
|
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = (*dataptr << 8) + *(dataptr + 1);
|
|
|
|
dataptr += 2;
|
2017-03-02 13:20:11 +00:00
|
|
|
printf(" design filename = \"%s\"\n", dataptr);
|
|
|
|
dataptr += length;
|
2013-04-26 11:12:07 +00:00
|
|
|
|
|
|
|
/* get part number (identifier, length, string) */
|
|
|
|
if (*dataptr++ != 0x62) {
|
|
|
|
printf("%s: Part number id not recognized in bitstream\n",
|
|
|
|
__func__);
|
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = (*dataptr << 8) + *(dataptr + 1);
|
|
|
|
dataptr += 2;
|
2013-04-26 13:04:48 +00:00
|
|
|
|
|
|
|
if (xdesc->name) {
|
2017-03-02 13:20:11 +00:00
|
|
|
i = (ulong)strstr((char *)dataptr, xdesc->name);
|
2016-01-11 07:00:41 +00:00
|
|
|
if (!i) {
|
2013-04-26 13:04:48 +00:00
|
|
|
printf("%s: Wrong bitstream ID for this device\n",
|
|
|
|
__func__);
|
|
|
|
printf("%s: Bitstream ID %s, current device ID %d/%s\n",
|
2017-03-02 13:20:11 +00:00
|
|
|
__func__, dataptr, devnum, xdesc->name);
|
2013-04-26 13:04:48 +00:00
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
} else {
|
2014-03-13 11:49:21 +00:00
|
|
|
printf("%s: Please fill correct device ID to xilinx_desc\n",
|
2013-04-26 13:04:48 +00:00
|
|
|
__func__);
|
|
|
|
}
|
2017-03-02 13:20:11 +00:00
|
|
|
printf(" part number = \"%s\"\n", dataptr);
|
|
|
|
dataptr += length;
|
2013-04-26 11:12:07 +00:00
|
|
|
|
|
|
|
/* get date (identifier, length, string) */
|
|
|
|
if (*dataptr++ != 0x63) {
|
|
|
|
printf("%s: Date identifier not recognized in bitstream\n",
|
|
|
|
__func__);
|
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = (*dataptr << 8) + *(dataptr+1);
|
|
|
|
dataptr += 2;
|
2017-03-02 13:20:11 +00:00
|
|
|
printf(" date = \"%s\"\n", dataptr);
|
|
|
|
dataptr += length;
|
2013-04-26 11:12:07 +00:00
|
|
|
|
|
|
|
/* get time (identifier, length, string) */
|
|
|
|
if (*dataptr++ != 0x64) {
|
|
|
|
printf("%s: Time identifier not recognized in bitstream\n",
|
|
|
|
__func__);
|
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = (*dataptr << 8) + *(dataptr+1);
|
|
|
|
dataptr += 2;
|
2017-03-02 13:20:11 +00:00
|
|
|
printf(" time = \"%s\"\n", dataptr);
|
|
|
|
dataptr += length;
|
2013-04-26 11:12:07 +00:00
|
|
|
|
|
|
|
/* get fpga data length (identifier, length) */
|
|
|
|
if (*dataptr++ != 0x65) {
|
|
|
|
printf("%s: Data length id not recognized in bitstream\n",
|
|
|
|
__func__);
|
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
swapsize = ((unsigned int) *dataptr << 24) +
|
|
|
|
((unsigned int) *(dataptr + 1) << 16) +
|
|
|
|
((unsigned int) *(dataptr + 2) << 8) +
|
|
|
|
((unsigned int) *(dataptr + 3));
|
|
|
|
dataptr += 4;
|
|
|
|
printf(" bytes in bitstream = %d\n", swapsize);
|
|
|
|
|
2014-05-02 12:09:30 +00:00
|
|
|
return fpga_load(devnum, dataptr, swapsize, bstype);
|
2013-04-26 11:12:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 12:09:30 +00:00
|
|
|
int xilinx_load(xilinx_desc *desc, const void *buf, size_t bsize,
|
|
|
|
bitstream_type bstype)
|
2002-08-21 22:08:56 +00:00
|
|
|
{
|
2005-10-13 14:45:02 +00:00
|
|
|
if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
|
2002-08-21 22:08:56 +00:00
|
|
|
printf ("%s: Invalid device descriptor\n", __FUNCTION__);
|
2014-03-13 12:07:57 +00:00
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
2002-08-21 22:08:56 +00:00
|
|
|
|
2014-07-16 08:31:21 +00:00
|
|
|
if (!desc->operations || !desc->operations->load) {
|
|
|
|
printf("%s: Missing load operation\n", __func__);
|
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
|
2014-05-02 12:09:30 +00:00
|
|
|
return desc->operations->load(desc, buf, bsize, bstype);
|
2002-08-21 22:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-03-14 11:05:37 +00:00
|
|
|
#if defined(CONFIG_CMD_FPGA_LOADFS)
|
|
|
|
int xilinx_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,
|
|
|
|
fpga_fs_info *fpga_fsinfo)
|
|
|
|
{
|
|
|
|
if (!xilinx_validate(desc, (char *)__func__)) {
|
|
|
|
printf("%s: Invalid device descriptor\n", __func__);
|
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
|
2014-07-16 08:31:21 +00:00
|
|
|
if (!desc->operations || !desc->operations->loadfs) {
|
|
|
|
printf("%s: Missing loadfs operation\n", __func__);
|
2014-03-14 11:05:37 +00:00
|
|
|
return FPGA_FAIL;
|
2014-07-16 08:31:21 +00:00
|
|
|
}
|
2014-03-14 11:05:37 +00:00
|
|
|
|
|
|
|
return desc->operations->loadfs(desc, buf, bsize, fpga_fsinfo);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-05-31 09:40:23 +00:00
|
|
|
#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
|
|
|
|
int xilinx_loads(xilinx_desc *desc, const void *buf, size_t bsize,
|
|
|
|
struct fpga_secure_info *fpga_sec_info)
|
|
|
|
{
|
|
|
|
if (!xilinx_validate(desc, (char *)__func__)) {
|
|
|
|
printf("%s: Invalid device descriptor\n", __func__);
|
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!desc->operations || !desc->operations->loads) {
|
|
|
|
printf("%s: Missing loads operation\n", __func__);
|
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return desc->operations->loads(desc, buf, bsize, fpga_sec_info);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-13 11:49:21 +00:00
|
|
|
int xilinx_dump(xilinx_desc *desc, const void *buf, size_t bsize)
|
2002-08-21 22:08:56 +00:00
|
|
|
{
|
2005-10-13 14:45:02 +00:00
|
|
|
if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
|
2002-08-21 22:08:56 +00:00
|
|
|
printf ("%s: Invalid device descriptor\n", __FUNCTION__);
|
2014-03-13 12:07:57 +00:00
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
2002-08-21 22:08:56 +00:00
|
|
|
|
2014-07-16 08:31:21 +00:00
|
|
|
if (!desc->operations || !desc->operations->dump) {
|
|
|
|
printf("%s: Missing dump operation\n", __func__);
|
|
|
|
return FPGA_FAIL;
|
|
|
|
}
|
|
|
|
|
2014-03-13 12:07:57 +00:00
|
|
|
return desc->operations->dump(desc, buf, bsize);
|
2002-08-21 22:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 11:49:21 +00:00
|
|
|
int xilinx_info(xilinx_desc *desc)
|
2002-08-21 22:08:56 +00:00
|
|
|
{
|
|
|
|
int ret_val = FPGA_FAIL;
|
|
|
|
|
2005-10-13 14:45:02 +00:00
|
|
|
if (xilinx_validate (desc, (char *)__FUNCTION__)) {
|
2002-08-21 22:08:56 +00:00
|
|
|
printf ("Family: \t");
|
|
|
|
switch (desc->family) {
|
2014-03-13 10:23:43 +00:00
|
|
|
case xilinx_spartan2:
|
2002-08-21 22:08:56 +00:00
|
|
|
printf ("Spartan-II\n");
|
|
|
|
break;
|
2014-03-13 10:28:42 +00:00
|
|
|
case xilinx_spartan3:
|
2005-09-25 14:44:21 +00:00
|
|
|
printf ("Spartan-III\n");
|
|
|
|
break;
|
2014-03-13 10:33:36 +00:00
|
|
|
case xilinx_virtex2:
|
2002-08-21 22:08:56 +00:00
|
|
|
printf ("Virtex-II\n");
|
|
|
|
break;
|
2013-04-22 13:43:02 +00:00
|
|
|
case xilinx_zynq:
|
|
|
|
printf("Zynq PL\n");
|
|
|
|
break;
|
2016-01-13 10:55:37 +00:00
|
|
|
case xilinx_zynqmp:
|
|
|
|
printf("ZynqMP PL\n");
|
|
|
|
break;
|
2019-08-05 10:24:59 +00:00
|
|
|
case xilinx_versal:
|
|
|
|
printf("Versal PL\n");
|
|
|
|
break;
|
|
|
|
/* Add new family types here */
|
2002-08-21 22:08:56 +00:00
|
|
|
default:
|
|
|
|
printf ("Unknown family type, %d\n", desc->family);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("Interface type:\t");
|
|
|
|
switch (desc->iface) {
|
|
|
|
case slave_serial:
|
|
|
|
printf ("Slave Serial\n");
|
|
|
|
break;
|
|
|
|
case master_serial: /* Not used */
|
|
|
|
printf ("Master Serial\n");
|
|
|
|
break;
|
|
|
|
case slave_parallel:
|
|
|
|
printf ("Slave Parallel\n");
|
|
|
|
break;
|
|
|
|
case jtag_mode: /* Not used */
|
|
|
|
printf ("JTAG Mode\n");
|
|
|
|
break;
|
|
|
|
case slave_selectmap:
|
|
|
|
printf ("Slave SelectMap Mode\n");
|
|
|
|
break;
|
|
|
|
case master_selectmap:
|
|
|
|
printf ("Master SelectMap Mode\n");
|
|
|
|
break;
|
2013-04-22 13:43:02 +00:00
|
|
|
case devcfg:
|
|
|
|
printf("Device configuration interface (Zynq)\n");
|
|
|
|
break;
|
2016-01-13 10:55:37 +00:00
|
|
|
case csu_dma:
|
|
|
|
printf("csu_dma configuration interface (ZynqMP)\n");
|
|
|
|
break;
|
2019-08-05 10:24:59 +00:00
|
|
|
case cfi:
|
|
|
|
printf("CFI configuration interface (Versal)\n");
|
|
|
|
break;
|
2002-08-21 22:08:56 +00:00
|
|
|
/* Add new interface types here */
|
|
|
|
default:
|
|
|
|
printf ("Unsupported interface type, %d\n", desc->iface);
|
|
|
|
}
|
|
|
|
|
2014-06-08 04:07:58 +00:00
|
|
|
printf("Device Size: \t%zd bytes\n"
|
|
|
|
"Cookie: \t0x%x (%d)\n",
|
|
|
|
desc->size, desc->cookie, desc->cookie);
|
2013-04-26 13:04:48 +00:00
|
|
|
if (desc->name)
|
|
|
|
printf("Device name: \t%s\n", desc->name);
|
2002-08-21 22:08:56 +00:00
|
|
|
|
2014-07-16 08:36:42 +00:00
|
|
|
if (desc->iface_fns)
|
2002-08-21 22:08:56 +00:00
|
|
|
printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
|
2014-07-16 08:36:42 +00:00
|
|
|
else
|
2002-08-21 22:08:56 +00:00
|
|
|
printf ("No Device Function Table.\n");
|
|
|
|
|
2014-07-16 08:36:42 +00:00
|
|
|
if (desc->operations && desc->operations->info)
|
|
|
|
desc->operations->info(desc);
|
|
|
|
|
2002-08-21 22:08:56 +00:00
|
|
|
ret_val = FPGA_SUCCESS;
|
|
|
|
} else {
|
|
|
|
printf ("%s: Invalid device descriptor\n", __FUNCTION__);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2014-03-13 11:49:21 +00:00
|
|
|
static int xilinx_validate(xilinx_desc *desc, char *fn)
|
2002-08-21 22:08:56 +00:00
|
|
|
{
|
2013-04-01 18:29:11 +00:00
|
|
|
int ret_val = false;
|
2002-08-21 22:08:56 +00:00
|
|
|
|
|
|
|
if (desc) {
|
|
|
|
if ((desc->family > min_xilinx_type) &&
|
|
|
|
(desc->family < max_xilinx_type)) {
|
|
|
|
if ((desc->iface > min_xilinx_iface_type) &&
|
|
|
|
(desc->iface < max_xilinx_iface_type)) {
|
|
|
|
if (desc->size) {
|
2013-04-01 18:29:11 +00:00
|
|
|
ret_val = true;
|
2002-08-21 22:08:56 +00:00
|
|
|
} else
|
|
|
|
printf ("%s: NULL part size\n", fn);
|
|
|
|
} else
|
|
|
|
printf ("%s: Invalid Interface type, %d\n",
|
|
|
|
fn, desc->iface);
|
|
|
|
} else
|
|
|
|
printf ("%s: Invalid family type, %d\n", fn, desc->family);
|
|
|
|
} else
|
|
|
|
printf ("%s: NULL descriptor!\n", fn);
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|