[U-Boot] [PATCH v2 7/7] fpga: Check device name against bitstream name

Michal Simek michal.simek at xilinx.com
Wed May 1 10:59:23 CEST 2013


Ensure that wrong bitstream won't be loaded
to current device.

Signed-off-by: Michal Simek <michal.simek at xilinx.com>

---
Changes in v2:
- New patch in this series

 drivers/fpga/fpga.c   | 20 ++++++++++++++++++++
 drivers/fpga/xilinx.c |  2 ++
 include/xilinx.h      |  1 +
 include/zynqpl.h      |  8 ++++----
 4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c
index b74c84f..5ba8cf0 100644
--- a/drivers/fpga/fpga.c
+++ b/drivers/fpga/fpga.c
@@ -197,8 +197,14 @@ int fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size)
 	unsigned char *dataptr;
 	unsigned int i;
 	int rc;
+	const fpga_desc *desc;
+	Xilinx_desc *xdesc;

 	dataptr = (unsigned char *)fpgadata;
+	/* Find out fpga_description */
+	desc = fpga_validate(dev, dataptr, 0, (char *)__func__);
+	/* Assign xilinx device description */
+	xdesc = desc->devdesc;

 	/* skip the first bytes of the bitsteam, their meaning is unknown */
 	length = (*dataptr << 8) + *(dataptr + 1);
@@ -232,6 +238,20 @@ int fpga_loadbitstream(unsigned long dev, char *fpgadata, size_t size)
 	dataptr += 2;
 	for (i = 0; i < length; i++)
 		buffer[i] = *dataptr++;
+
+	if (xdesc->name) {
+		i = strncmp(buffer, xdesc->name, strlen(xdesc->name));
+		if (i) {
+			printf("%s: Wrong bitstream ID for this device\n",
+			       __func__);
+			printf("%s: Bitstream ID %s, current device ID %d/%s\n",
+			       __func__, dev, xdesc->name, buffer);
+			return FPGA_FAIL;
+		}
+	} else {
+		printf("%s: Please fill correct device ID to Xilinx_desc\n",
+		       __func__);
+	}
 	printf("  part number = \"%s\"\n", buffer);

 	/* get date (identifier, length, string) */
diff --git a/drivers/fpga/xilinx.c b/drivers/fpga/xilinx.c
index fe324ab..bd740c2 100644
--- a/drivers/fpga/xilinx.c
+++ b/drivers/fpga/xilinx.c
@@ -220,6 +220,8 @@ int xilinx_info (Xilinx_desc * desc)
 		printf ("Device Size:   \t%d bytes\n"
 				"Cookie:        \t0x%x (%d)\n",
 				desc->size, desc->cookie, desc->cookie);
+		if (desc->name)
+			printf("Device name:   \t%s\n", desc->name);

 		if (desc->iface_fns) {
 			printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
diff --git a/include/xilinx.h b/include/xilinx.h
index 592cbea..bcfe76d 100644
--- a/include/xilinx.h
+++ b/include/xilinx.h
@@ -81,6 +81,7 @@ typedef struct {		/* typedef Xilinx_desc */
 	size_t size;		/* bytes of data part can accept */
 	void *iface_fns;	/* interface function table */
 	int cookie;		/* implementation specific cookie */
+	char *name;		/* device name in bitstream */
 } Xilinx_desc;			/* end, typedef Xilinx_desc */

 /* Generic Xilinx Functions
diff --git a/include/zynqpl.h b/include/zynqpl.h
index bc9b948..0247ef6 100644
--- a/include/zynqpl.h
+++ b/include/zynqpl.h
@@ -45,15 +45,15 @@ extern int zynq_info(Xilinx_desc *desc);

 /* Descriptor Macros */
 #define XILINX_XC7Z010_DESC(cookie) \
-{ xilinx_zynq, devcfg, XILINX_XC7Z010_SIZE, NULL, cookie }
+{ xilinx_zynq, devcfg, XILINX_XC7Z010_SIZE, NULL, cookie, "7z010" }

 #define XILINX_XC7Z020_DESC(cookie) \
-{ xilinx_zynq, devcfg, XILINX_XC7Z020_SIZE, NULL, cookie }
+{ xilinx_zynq, devcfg, XILINX_XC7Z020_SIZE, NULL, cookie, "7z020" }

 #define XILINX_XC7Z030_DESC(cookie) \
-{ xilinx_zynq, devcfg, XILINX_XC7Z030_SIZE, NULL, cookie }
+{ xilinx_zynq, devcfg, XILINX_XC7Z030_SIZE, NULL, cookie, "7z030" }

 #define XILINX_XC7Z045_DESC(cookie) \
-{ xilinx_zynq, devcfg, XILINX_XC7Z045_SIZE, NULL, cookie }
+{ xilinx_zynq, devcfg, XILINX_XC7Z045_SIZE, NULL, cookie, "7z045" }

 #endif /* _ZYNQPL_H_ */
--
1.8.2.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130501/79e65497/attachment.pgp>


More information about the U-Boot mailing list