[U-Boot] [PATCH] fpga: allow programming fpga from FIT image for all FPGA drivers

Goldschmidt Simon sgoldschmidt at de.pepperl-fuchs.com
Fri Nov 10 14:17:41 UTC 2017


This drops the limit that fpga is only loaded from FIT images for Xilinx.
This is done by moving the 'partial' check from 'common/image.c' to
'drivers/fpga/xilinx.c' (the only driver supporting partial images yet)
and supplies a weak default implementation in 'drivers/fpga/fpga.c'.

Signed-off-by: Simon Goldschmidt <sgoldschmidt at de.pepperl-fuchs.com>
---
 common/bootm.c        |  2 +-
 common/image.c        |  6 ++----
 drivers/fpga/fpga.c   |  9 +++++++++
 drivers/fpga/xilinx.c | 13 +++++++++++++
 include/fpga.h        |  1 +
 5 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 9493a306cd..adb12137c7 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -248,7 +248,7 @@ int bootm_find_images(int flag, int argc, char * const argv[])
 #endif
 
 #if IMAGE_ENABLE_FIT
-#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+#if defined(CONFIG_FPGA)
 	/* find bitstreams */
 	ret = boot_get_fpga(argc, argv, &images, IH_ARCH_DEFAULT,
 			    NULL, NULL);
diff --git a/common/image.c b/common/image.c
index 06fdca129c..9fd72b9423 100644
--- a/common/image.c
+++ b/common/image.c
@@ -1223,7 +1223,7 @@ int boot_get_setup(bootm_headers_t *images, uint8_t arch,
 }
 
 #if IMAGE_ENABLE_FIT
-#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+#if defined(CONFIG_FPGA)
 int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
 		  uint8_t arch, const ulong *ld_start, ulong * const ld_len)
 {
@@ -1234,8 +1234,6 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
 	const char *uname, *name;
 	int err;
 	int devnum = 0; /* TODO support multi fpga platforms */
-	const fpga_desc * const desc = fpga_get_desc(devnum);
-	xilinx_desc *desc_xilinx = desc->devdesc;
 
 	/* Check to see if the images struct has a FIT configuration */
 	if (!genimg_has_config(images)) {
@@ -1280,7 +1278,7 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
 			return fit_img_result;
 		}
 
-		if (img_len >= desc_xilinx->size) {
+		if (!fpga_is_partial_data(devnum, img_len)) {
 			name = "full";
 			err = fpga_loadbitstream(devnum, (char *)img_data,
 						 img_len, BIT_FULL);
diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c
index e0fb1b4e78..6aead27f16 100644
--- a/drivers/fpga/fpga.c
+++ b/drivers/fpga/fpga.c
@@ -171,6 +171,15 @@ int fpga_add(fpga_type devtype, void *desc)
 }
 
 /*
+ * Return 1 if the fpga data is partial.
+ * This is only required for fpga drivers that support bitstream_type.
+ */
+int __weak fpga_is_partial_data(int devnum, size_t img_len)
+{
+	return 0;
+}
+
+/*
  * Convert bitstream data and load into the fpga
  */
 int __weak fpga_loadbitstream(int devnum, char *fpgadata, size_t size,
diff --git a/drivers/fpga/xilinx.c b/drivers/fpga/xilinx.c
index 941f30010a..3c05760969 100644
--- a/drivers/fpga/xilinx.c
+++ b/drivers/fpga/xilinx.c
@@ -24,6 +24,19 @@ static int xilinx_validate(xilinx_desc *desc, char *fn);
 
 /* ------------------------------------------------------------------------- */
 
+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;
+}
+
 int fpga_loadbitstream(int devnum, char *fpgadata, size_t size,
 		       bitstream_type bstype)
 {
diff --git a/include/fpga.h b/include/fpga.h
index d768fb1417..4d6da790b7 100644
--- a/include/fpga.h
+++ b/include/fpga.h
@@ -54,6 +54,7 @@ void fpga_init(void);
 int fpga_add(fpga_type devtype, void *desc);
 int fpga_count(void);
 const fpga_desc *const fpga_get_desc(int devnum);
+int fpga_is_partial_data(int devnum, size_t img_len);
 int fpga_load(int devnum, const void *buf, size_t bsize,
 	      bitstream_type bstype);
 int fpga_fsload(int devnum, const void *buf, size_t size,
-- 
2.12.2.windows.2



More information about the U-Boot mailing list