]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fpga: Check device name against bitstream name
authorMichal Simek <michal.simek@xilinx.com>
Fri, 26 Apr 2013 13:04:48 +0000 (15:04 +0200)
committerMichal Simek <michal.simek@xilinx.com>
Mon, 6 May 2013 08:41:25 +0000 (10:41 +0200)
Ensure that wrong bitstream won't be loaded
to current device.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@ti.com>
drivers/fpga/fpga.c
drivers/fpga/xilinx.c
include/fpga.h
include/xilinx.h
include/zynqpl.h

index 244f503240170632eeeb9eea6fa7c15d53a6282b..f70bff6ed177aea8cad8d324687ddaa397ae0277 100644 (file)
@@ -72,8 +72,8 @@ static const fpga_desc *const fpga_get_desc(int devnum)
  * fpga_validate
  *     generic parameter checking code
  */
-static const fpga_desc *const fpga_validate(int devnum, const void *buf,
-                                        size_t bsize, char *fn)
+const fpga_desc *const fpga_validate(int devnum, const void *buf,
+                                    size_t bsize, char *fn)
 {
        const fpga_desc *desc = fpga_get_desc(devnum);
 
index 496aa2f6eb750cf066946e315e3dbe7b9ec1de4a..49e943718e2a045d93ebb78e6a72ab0db50abbf2 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 #include <common.h>
+#include <fpga.h>
 #include <virtex2.h>
 #include <spartan2.h>
 #include <spartan3.h>
@@ -58,8 +59,14 @@ int fpga_loadbitstream(int devnum, char *fpgadata, size_t size)
        char buffer[80];
        unsigned char *dataptr;
        unsigned int i;
+       const fpga_desc *desc;
+       Xilinx_desc *xdesc;
 
        dataptr = (unsigned char *)fpgadata;
+       /* Find out fpga_description */
+       desc = fpga_validate(devnum, 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);
@@ -93,6 +100,20 @@ int fpga_loadbitstream(int devnum, 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__, buffer, devnum, xdesc->name);
+                       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) */
@@ -306,6 +327,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);
index 38f62c0c2aaeff9cda1ea758fe54ef3f039328a1..ebefba8d05f35bbcee663dfa8b7b6cc688c547ca 100644 (file)
@@ -71,5 +71,7 @@ extern int fpga_load(int devnum, const void *buf, size_t bsize);
 extern int fpga_loadbitstream(int devnum, char *fpgadata, size_t size);
 extern int fpga_dump(int devnum, const void *buf, size_t bsize);
 extern int fpga_info(int devnum);
+extern const fpga_desc *const fpga_validate(int devnum, const void *buf,
+                                           size_t bsize, char *fn);
 
 #endif /* _FPGA_H_ */
index 592cbea1f301ad452f904621f41dc77786a3d1d2..bcfe76d81ef07bf0050ed5b699e4d244dd3f5d30 100644 (file)
@@ -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
index bc9b94815950616db1ca60768a673f964096e3ea..0247ef61cce1354b336a711319f6cab058261be5 100644 (file)
@@ -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_ */