summaryrefslogtreecommitdiff
path: root/drivers/fpga
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/fpga')
-rw-r--r--drivers/fpga/Kconfig27
-rw-r--r--drivers/fpga/fpga.c33
-rw-r--r--drivers/fpga/spartan2.c3
-rw-r--r--drivers/fpga/spartan3.c2
-rw-r--r--drivers/fpga/versalpl.c2
-rw-r--r--drivers/fpga/virtex2.c13
-rw-r--r--drivers/fpga/xilinx.c8
-rw-r--r--drivers/fpga/zynqmppl.c99
-rw-r--r--drivers/fpga/zynqpl.c2
9 files changed, 150 insertions, 39 deletions
diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig
index 76719517f54..e07a9cf80ea 100644
--- a/drivers/fpga/Kconfig
+++ b/drivers/fpga/Kconfig
@@ -91,4 +91,31 @@ config FPGA_ZYNQPL
Enable FPGA driver for loading bitstream in BIT and BIN format
on Xilinx Zynq devices.
+config SYS_FPGA_CHECK_CTRLC
+ bool "Allow Control-C to interrupt FPGA configuration"
+ depends on FPGA
+ help
+ User can interrupt FPGA configuration by pressing CTRL+C.
+
+config SYS_FPGA_PROG_FEEDBACK
+ bool "Progress output during FPGA configuration"
+ depends on FPGA
+ default y if FPGA_VIRTEX2
+ help
+ Enable printing of hash marks during FPGA configuration.
+
+config FPGA_LOAD_SECURE
+ bool "Enable loading secure bitstreams"
+ depends on FPGA
+ help
+ Enables the fpga loads() functions that are used to load secure
+ (authenticated or encrypted or both) bitstreams on to FPGA.
+
+config SPL_FPGA_LOAD_SECURE
+ bool "Enable loading secure bitstreams for SPL"
+ depends on SPL_FPGA
+ help
+ Enables the fpga loads() functions that are used to load secure
+ (authenticated or encrypted or both) bitstreams on to FPGA.
+
endmenu
diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c
index fe3dfa12335..4db5c0a91e9 100644
--- a/drivers/fpga/fpga.c
+++ b/drivers/fpga/fpga.c
@@ -220,7 +220,7 @@ int fpga_fsload(int devnum, const void *buf, size_t size,
}
#endif
-#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
int fpga_loads(int devnum, const void *buf, size_t size,
struct fpga_secure_info *fpga_sec_info)
{
@@ -252,7 +252,8 @@ int fpga_loads(int devnum, const void *buf, size_t size,
/*
* Generic multiplexing code
*/
-int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype)
+int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype,
+ int flags)
{
int ret_val = FPGA_FAIL; /* assume failure */
const fpga_desc *desc = fpga_validate(devnum, buf, bsize,
@@ -263,7 +264,7 @@ int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype)
case fpga_xilinx:
#if defined(CONFIG_FPGA_XILINX)
ret_val = xilinx_load(desc->devdesc, buf, bsize,
- bstype);
+ bstype, flags);
#else
fpga_no_sup((char *)__func__, "Xilinx devices");
#endif
@@ -356,3 +357,29 @@ int fpga_info(int devnum)
return fpga_dev_info(devnum);
}
+
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+int fpga_compatible2flag(int devnum, const char *compatible)
+{
+ const fpga_desc * const desc = fpga_get_desc(devnum);
+
+ if (!desc)
+ return 0;
+
+ switch (desc->devtype) {
+#if defined(CONFIG_FPGA_XILINX)
+ case fpga_xilinx:
+ {
+ xilinx_desc *xdesc = (xilinx_desc *)desc->devdesc;
+
+ if (xdesc->operations && xdesc->operations->str2flag)
+ return xdesc->operations->str2flag(xdesc, compatible);
+ }
+#endif
+ default:
+ break;
+ }
+
+ return 0;
+}
+#endif
diff --git a/drivers/fpga/spartan2.c b/drivers/fpga/spartan2.c
index 3435400e58b..47692e32076 100644
--- a/drivers/fpga/spartan2.c
+++ b/drivers/fpga/spartan2.c
@@ -15,7 +15,6 @@
#endif
#undef CONFIG_SYS_FPGA_CHECK_BUSY
-#undef CONFIG_SYS_FPGA_PROG_FEEDBACK
/* Note: The assumption is that we cannot possibly run fast enough to
* overrun the device (the Slave Parallel mode can free run at 50MHz).
@@ -41,7 +40,7 @@ static int spartan2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize);
/* ------------------------------------------------------------------------- */
/* Spartan-II Generic Implementation */
static int spartan2_load(xilinx_desc *desc, const void *buf, size_t bsize,
- bitstream_type bstype)
+ bitstream_type bstype, int flags)
{
int ret_val = FPGA_FAIL;
diff --git a/drivers/fpga/spartan3.c b/drivers/fpga/spartan3.c
index 4850c99352d..918f6db5065 100644
--- a/drivers/fpga/spartan3.c
+++ b/drivers/fpga/spartan3.c
@@ -45,7 +45,7 @@ static int spartan3_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize);
/* ------------------------------------------------------------------------- */
/* Spartan-II Generic Implementation */
static int spartan3_load(xilinx_desc *desc, const void *buf, size_t bsize,
- bitstream_type bstype)
+ bitstream_type bstype, int flags)
{
int ret_val = FPGA_FAIL;
diff --git a/drivers/fpga/versalpl.c b/drivers/fpga/versalpl.c
index c44a7d34557..d3876a8f541 100644
--- a/drivers/fpga/versalpl.c
+++ b/drivers/fpga/versalpl.c
@@ -27,7 +27,7 @@ static ulong versal_align_dma_buffer(ulong *buf, u32 len)
}
static int versal_load(xilinx_desc *desc, const void *buf, size_t bsize,
- bitstream_type bstype)
+ bitstream_type bstype, int flags)
{
ulong bin_buf;
int ret;
diff --git a/drivers/fpga/virtex2.c b/drivers/fpga/virtex2.c
index b3e0537bab0..51b8d312056 100644
--- a/drivers/fpga/virtex2.c
+++ b/drivers/fpga/virtex2.c
@@ -41,17 +41,6 @@
#define CONFIG_FPGA_DELAY()
#endif
-#ifndef CONFIG_SYS_FPGA_PROG_FEEDBACK
-#define CONFIG_SYS_FPGA_PROG_FEEDBACK
-#endif
-
-/*
- * Don't allow config cycle to be interrupted
- */
-#ifndef CONFIG_SYS_FPGA_CHECK_CTRLC
-#undef CONFIG_SYS_FPGA_CHECK_CTRLC
-#endif
-
/*
* Check for errors during configuration by default
*/
@@ -94,7 +83,7 @@ static int virtex2_ss_load(xilinx_desc *desc, const void *buf, size_t bsize);
static int virtex2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize);
static int virtex2_load(xilinx_desc *desc, const void *buf, size_t bsize,
- bitstream_type bstype)
+ bitstream_type bstype, int flags)
{
int ret_val = FPGA_FAIL;
diff --git a/drivers/fpga/xilinx.c b/drivers/fpga/xilinx.c
index cbebefb55fe..8170c3368ef 100644
--- a/drivers/fpga/xilinx.c
+++ b/drivers/fpga/xilinx.c
@@ -135,11 +135,11 @@ int fpga_loadbitstream(int devnum, char *fpgadata, size_t size,
dataptr += 4;
printf(" bytes in bitstream = %d\n", swapsize);
- return fpga_load(devnum, dataptr, swapsize, bstype);
+ return fpga_load(devnum, dataptr, swapsize, bstype, 0);
}
int xilinx_load(xilinx_desc *desc, const void *buf, size_t bsize,
- bitstream_type bstype)
+ bitstream_type bstype, int flags)
{
if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
printf ("%s: Invalid device descriptor\n", __FUNCTION__);
@@ -151,7 +151,7 @@ int xilinx_load(xilinx_desc *desc, const void *buf, size_t bsize,
return FPGA_FAIL;
}
- return desc->operations->load(desc, buf, bsize, bstype);
+ return desc->operations->load(desc, buf, bsize, bstype, flags);
}
#if defined(CONFIG_CMD_FPGA_LOADFS)
@@ -172,7 +172,7 @@ int xilinx_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,
}
#endif
-#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
int xilinx_loads(xilinx_desc *desc, const void *buf, size_t bsize,
struct fpga_secure_info *fpga_sec_info)
{
diff --git a/drivers/fpga/zynqmppl.c b/drivers/fpga/zynqmppl.c
index 6b394869dbf..d1491da02c3 100644
--- a/drivers/fpga/zynqmppl.c
+++ b/drivers/fpga/zynqmppl.c
@@ -9,6 +9,7 @@
#include <common.h>
#include <compiler.h>
#include <cpu_func.h>
+#include <fpga.h>
#include <log.h>
#include <zynqmppl.h>
#include <zynqmp_firmware.h>
@@ -199,53 +200,106 @@ static int zynqmp_validate_bitstream(xilinx_desc *desc, const void *buf,
return 0;
}
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+static int zynqmp_check_compatible(xilinx_desc *desc, int flags)
+{
+ /*
+ * If no flags set, the image may be legacy, but we need to
+ * signal caller this situation with specific error code.
+ */
+ if (!flags)
+ return -ENODATA;
+
+ /* For legacy bitstream images no need for other methods exist */
+ if ((flags & desc->flags) && flags == FPGA_LEGACY)
+ return 0;
+
+ /*
+ * Other images are handled in secure callback loads(). Check
+ * callback existence besides image type support.
+ */
+ if (desc->operations->loads && (flags & desc->flags))
+ return 0;
+
+ return -ENODEV;
+}
+#endif
+
static int zynqmp_load(xilinx_desc *desc, const void *buf, size_t bsize,
- bitstream_type bstype)
+ bitstream_type bstype, int flags)
{
ALLOC_CACHE_ALIGN_BUFFER(u32, bsizeptr, 1);
u32 swap = 0;
ulong bin_buf;
int ret;
u32 buf_lo, buf_hi;
+ u32 bsize_req = (u32)bsize;
u32 ret_payload[PAYLOAD_ARG_CNT];
- bool xilfpga_old = false;
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+ struct fpga_secure_info info = { 0 };
+
+ ret = zynqmp_check_compatible(desc, flags);
+ if (ret) {
+ if (ret != -ENODATA) {
+ puts("Missing loads() operation or unsupported bitstream type\n");
+ return FPGA_FAIL;
+ }
+ /* If flags is not set, the image treats as legacy */
+ flags = FPGA_LEGACY;
+ }
+
+ switch (flags) {
+ case FPGA_LEGACY:
+ break; /* Handle the legacy image later in this function */
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+ case FPGA_XILINX_ZYNQMP_DDRAUTH:
+ /* DDR authentication */
+ info.authflag = ZYNQMP_FPGA_AUTH_DDR;
+ info.encflag = FPGA_NO_ENC_OR_NO_AUTH;
+ return desc->operations->loads(desc, buf, bsize, &info);
+ case FPGA_XILINX_ZYNQMP_ENC:
+ /* Encryption using device key */
+ info.authflag = FPGA_NO_ENC_OR_NO_AUTH;
+ info.encflag = FPGA_ENC_DEV_KEY;
+ return desc->operations->loads(desc, buf, bsize, &info);
+#endif
+ default:
+ printf("Unsupported bitstream type %d\n", flags);
+ return FPGA_FAIL;
+ }
+#endif
if (zynqmp_firmware_version() <= PMUFW_V1_0) {
puts("WARN: PMUFW v1.0 or less is detected\n");
puts("WARN: Not all bitstream formats are supported\n");
puts("WARN: Please upgrade PMUFW\n");
- xilfpga_old = true;
if (zynqmp_validate_bitstream(desc, buf, bsize, bsize, &swap))
return FPGA_FAIL;
bsizeptr = (u32 *)&bsize;
flush_dcache_range((ulong)bsizeptr,
(ulong)bsizeptr + sizeof(size_t));
+ bsize_req = (u32)(uintptr_t)bsizeptr;
bstype |= BIT(ZYNQMP_FPGA_BIT_NS);
+ } else {
+ bstype = 0;
}
bin_buf = zynqmp_align_dma_buffer((u32 *)buf, bsize, swap);
- debug("%s called!\n", __func__);
flush_dcache_range(bin_buf, bin_buf + bsize);
buf_lo = (u32)bin_buf;
buf_hi = upper_32_bits(bin_buf);
- if (xilfpga_old)
- ret = xilinx_pm_request(PM_FPGA_LOAD, buf_lo,
- buf_hi, (u32)(uintptr_t)bsizeptr,
- bstype, ret_payload);
- else
- ret = xilinx_pm_request(PM_FPGA_LOAD, buf_lo,
- buf_hi, (u32)bsize, 0, ret_payload);
-
+ ret = xilinx_pm_request(PM_FPGA_LOAD, buf_lo, buf_hi,
+ bsize_req, bstype, ret_payload);
if (ret)
printf("PL FPGA LOAD failed with err: 0x%08x\n", ret);
return ret;
}
-#if defined(CONFIG_CMD_FPGA_LOAD_SECURE) && !defined(CONFIG_SPL_BUILD)
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
static int zynqmp_loads(xilinx_desc *desc, const void *buf, size_t bsize,
struct fpga_secure_info *fpga_sec_info)
{
@@ -304,10 +358,25 @@ static int zynqmp_pcap_info(xilinx_desc *desc)
return ret;
}
+static int __maybe_unused zynqmp_str2flag(xilinx_desc *desc, const char *str)
+{
+ if (!strncmp(str, "u-boot,fpga-legacy", 18))
+ return FPGA_LEGACY;
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+ if (!strncmp(str, "u-boot,zynqmp-fpga-ddrauth", 26))
+ return FPGA_XILINX_ZYNQMP_DDRAUTH;
+
+ if (!strncmp(str, "u-boot,zynqmp-fpga-enc", 22))
+ return FPGA_XILINX_ZYNQMP_ENC;
+#endif
+ return 0;
+}
+
struct xilinx_fpga_op zynqmp_op = {
.load = zynqmp_load,
-#if defined(CONFIG_CMD_FPGA_LOAD_SECURE) && !defined(CONFIG_SPL_BUILD)
+ .info = zynqmp_pcap_info,
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
.loads = zynqmp_loads,
+ .str2flag = zynqmp_str2flag,
#endif
- .info = zynqmp_pcap_info,
};
diff --git a/drivers/fpga/zynqpl.c b/drivers/fpga/zynqpl.c
index 2de40109a81..d8ebd542abd 100644
--- a/drivers/fpga/zynqpl.c
+++ b/drivers/fpga/zynqpl.c
@@ -371,7 +371,7 @@ static int zynq_validate_bitstream(xilinx_desc *desc, const void *buf,
}
static int zynq_load(xilinx_desc *desc, const void *buf, size_t bsize,
- bitstream_type bstype)
+ bitstream_type bstype, int flags)
{
unsigned long ts; /* Timestamp */
u32 isr_status, swap;