Patchwork [U-Boot,v2,4/7] cmd: fpga: Move fpga_loadbitstream to fpga.c

login
register
mail settings
Submitter Michal Simek
Date May 1, 2013, 8:59 a.m.
Message ID <f2aa08035905689cfd59cd524106e4962e62660d.1367398749.git.michal.simek@xilinx.com>
Download mbox | patch
Permalink /patch/240750/
State Superseded
Headers show

Comments

Michal Simek - May 1, 2013, 8:59 a.m.
In bitstream decoding you can directly check device
which you want to load and in fpga.c are fpga_validate
and fpga_dev_info functions which should be used for it.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---
Changes in v2: None

 common/cmd_fpga.c   | 94 -----------------------------------------------------
 drivers/fpga/fpga.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/fpga.h      |  1 +
 3 files changed, 95 insertions(+), 94 deletions(-)

--
1.8.2.1
Tom Rini - May 1, 2013, 3:03 p.m.
On Wed, May 01, 2013 at 10:59:20AM +0200, Michal Simek wrote:

> In bitstream decoding you can directly check device
> which you want to load and in fpga.c are fpga_validate
> and fpga_dev_info functions which should be used for it.
> 
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
[snip]
> +++ b/drivers/fpga/fpga.c
[snip]
> +#else
> +	printf("Bitstream support only for Xilinx devices\n");
> +	return FPGA_FAIL;
> +#endif

How about we re-work this as a __weak fpga_loadbitstream in
drivers/fpga/fpga.c that just says "Bitstream support not implemented
for this FPGA device", return FPGA_FAIL, and move the xilinx one into
drivers/fpga/xilinx.c ?
Michal Simek - May 1, 2013, 3:29 p.m.
On 05/01/2013 05:03 PM, Tom Rini wrote:
> On Wed, May 01, 2013 at 10:59:20AM +0200, Michal Simek wrote:
> 
>> In bitstream decoding you can directly check device
>> which you want to load and in fpga.c are fpga_validate
>> and fpga_dev_info functions which should be used for it.
>>
>> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> [snip]
>> +++ b/drivers/fpga/fpga.c
> [snip]
>> +#else
>> +	printf("Bitstream support only for Xilinx devices\n");
>> +	return FPGA_FAIL;
>> +#endif
> 
> How about we re-work this as a __weak fpga_loadbitstream in
> drivers/fpga/fpga.c that just says "Bitstream support not implemented
> for this FPGA device", return FPGA_FAIL, and move the xilinx one into
> drivers/fpga/xilinx.c ?

yep. Make sense to do it because at least from this code altera or lattice
don't support bitstream loading.
It will be more problematic if there is a board on the market
with different fpgas.

I even not sure if other fpga vendors have bitstream with any header
which should be used by this command.

Thanks,
Michal

Patch

diff --git a/common/cmd_fpga.c b/common/cmd_fpga.c
index f3579bb..aa14ceb 100644
--- a/common/cmd_fpga.c
+++ b/common/cmd_fpga.c
@@ -44,100 +44,6 @@  static int fpga_get_op(char *opstr);
 #define FPGA_DUMP   3
 #define FPGA_LOADMK 4

-/* Convert bitstream data and load into the fpga */
-int fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size)
-{
-#if defined(CONFIG_FPGA_XILINX)
-	unsigned int length;
-	unsigned int swapsize;
-	char buffer[80];
-	unsigned char *dataptr;
-	unsigned int i;
-	int rc;
-
-	dataptr = (unsigned char *)fpgadata;
-
-	/* 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;
-	for (i = 0; i < length; i++)
-		buffer[i] = *dataptr++;
-
-	printf("  design filename = \"%s\"\n", buffer);
-
-	/* 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;
-	for (i = 0; i < length; i++)
-		buffer[i] = *dataptr++;
-	printf("  part number = \"%s\"\n", buffer);
-
-	/* 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;
-	for (i = 0; i < length; i++)
-		buffer[i] = *dataptr++;
-	printf("  date = \"%s\"\n", buffer);
-
-	/* 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;
-	for (i = 0; i < length; i++)
-		buffer[i] = *dataptr++;
-	printf("  time = \"%s\"\n", buffer);
-
-	/* 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);
-
-	rc = fpga_load(dev, dataptr, swapsize);
-	return rc;
-#else
-	printf("Bitstream support only for Xilinx devices\n");
-	return FPGA_FAIL;
-#endif
-}
-
 /* ------------------------------------------------------------------------- */
 /* command form:
  *   fpga <op> <device number> <data addr> <datasize>
diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c
index 43bdf4f..b74c84f 100644
--- a/drivers/fpga/fpga.c
+++ b/drivers/fpga/fpga.c
@@ -187,6 +187,100 @@  int fpga_add(fpga_type devtype, void *desc)
 	return devnum;
 }

+/* Convert bitstream data and load into the fpga */
+int fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size)
+{
+#if defined(CONFIG_FPGA_XILINX)
+	unsigned int length;
+	unsigned int swapsize;
+	char buffer[80];
+	unsigned char *dataptr;
+	unsigned int i;
+	int rc;
+
+	dataptr = (unsigned char *)fpgadata;
+
+	/* 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;
+	for (i = 0; i < length; i++)
+		buffer[i] = *dataptr++;
+
+	printf("  design filename = \"%s\"\n", buffer);
+
+	/* 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;
+	for (i = 0; i < length; i++)
+		buffer[i] = *dataptr++;
+	printf("  part number = \"%s\"\n", buffer);
+
+	/* 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;
+	for (i = 0; i < length; i++)
+		buffer[i] = *dataptr++;
+	printf("  date = \"%s\"\n", buffer);
+
+	/* 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;
+	for (i = 0; i < length; i++)
+		buffer[i] = *dataptr++;
+	printf("  time = \"%s\"\n", buffer);
+
+	/* 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);
+
+	rc = fpga_load(dev, dataptr, swapsize);
+	return rc;
+#else
+	printf("Bitstream support only for Xilinx devices\n");
+	return FPGA_FAIL;
+#endif
+}
+
 /*
  * Generic multiplexing code
  */
diff --git a/include/fpga.h b/include/fpga.h
index 30a4e6a..0d01e04 100644
--- a/include/fpga.h
+++ b/include/fpga.h
@@ -68,6 +68,7 @@  extern void fpga_init(void);
 extern int fpga_add(fpga_type devtype, void *desc);
 extern int fpga_count(void);
 extern int fpga_load(int devnum, const void *buf, size_t bsize);
+extern int fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size);
 extern int fpga_dump(int devnum, const void *buf, size_t bsize);
 extern int fpga_info(int devnum);