Commit 6631db4773cd735688bf3332173a49271df23385
1 parent
d5dae85f23
Exists in
master
and in
53 other branches
fpga: Check device name against bitstream name
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>
Showing 5 changed files with 32 additions and 6 deletions Side-by-side Diff
drivers/fpga/fpga.c
... | ... | @@ -72,8 +72,8 @@ |
72 | 72 | * fpga_validate |
73 | 73 | * generic parameter checking code |
74 | 74 | */ |
75 | -static const fpga_desc *const fpga_validate(int devnum, const void *buf, | |
76 | - size_t bsize, char *fn) | |
75 | +const fpga_desc *const fpga_validate(int devnum, const void *buf, | |
76 | + size_t bsize, char *fn) | |
77 | 77 | { |
78 | 78 | const fpga_desc *desc = fpga_get_desc(devnum); |
79 | 79 |
drivers/fpga/xilinx.c
... | ... | @@ -30,6 +30,7 @@ |
30 | 30 | */ |
31 | 31 | |
32 | 32 | #include <common.h> |
33 | +#include <fpga.h> | |
33 | 34 | #include <virtex2.h> |
34 | 35 | #include <spartan2.h> |
35 | 36 | #include <spartan3.h> |
36 | 37 | |
... | ... | @@ -58,8 +59,14 @@ |
58 | 59 | char buffer[80]; |
59 | 60 | unsigned char *dataptr; |
60 | 61 | unsigned int i; |
62 | + const fpga_desc *desc; | |
63 | + Xilinx_desc *xdesc; | |
61 | 64 | |
62 | 65 | dataptr = (unsigned char *)fpgadata; |
66 | + /* Find out fpga_description */ | |
67 | + desc = fpga_validate(devnum, dataptr, 0, (char *)__func__); | |
68 | + /* Assign xilinx device description */ | |
69 | + xdesc = desc->devdesc; | |
63 | 70 | |
64 | 71 | /* skip the first bytes of the bitsteam, their meaning is unknown */ |
65 | 72 | length = (*dataptr << 8) + *(dataptr + 1); |
... | ... | @@ -93,6 +100,20 @@ |
93 | 100 | dataptr += 2; |
94 | 101 | for (i = 0; i < length; i++) |
95 | 102 | buffer[i] = *dataptr++; |
103 | + | |
104 | + if (xdesc->name) { | |
105 | + i = strncmp(buffer, xdesc->name, strlen(xdesc->name)); | |
106 | + if (i) { | |
107 | + printf("%s: Wrong bitstream ID for this device\n", | |
108 | + __func__); | |
109 | + printf("%s: Bitstream ID %s, current device ID %d/%s\n", | |
110 | + __func__, buffer, devnum, xdesc->name); | |
111 | + return FPGA_FAIL; | |
112 | + } | |
113 | + } else { | |
114 | + printf("%s: Please fill correct device ID to Xilinx_desc\n", | |
115 | + __func__); | |
116 | + } | |
96 | 117 | printf(" part number = \"%s\"\n", buffer); |
97 | 118 | |
98 | 119 | /* get date (identifier, length, string) */ |
... | ... | @@ -306,6 +327,8 @@ |
306 | 327 | printf ("Device Size: \t%d bytes\n" |
307 | 328 | "Cookie: \t0x%x (%d)\n", |
308 | 329 | desc->size, desc->cookie, desc->cookie); |
330 | + if (desc->name) | |
331 | + printf("Device name: \t%s\n", desc->name); | |
309 | 332 | |
310 | 333 | if (desc->iface_fns) { |
311 | 334 | printf ("Device Function Table @ 0x%p\n", desc->iface_fns); |
include/fpga.h
... | ... | @@ -71,6 +71,8 @@ |
71 | 71 | extern int fpga_loadbitstream(int devnum, char *fpgadata, size_t size); |
72 | 72 | extern int fpga_dump(int devnum, const void *buf, size_t bsize); |
73 | 73 | extern int fpga_info(int devnum); |
74 | +extern const fpga_desc *const fpga_validate(int devnum, const void *buf, | |
75 | + size_t bsize, char *fn); | |
74 | 76 | |
75 | 77 | #endif /* _FPGA_H_ */ |
include/xilinx.h
... | ... | @@ -81,6 +81,7 @@ |
81 | 81 | size_t size; /* bytes of data part can accept */ |
82 | 82 | void *iface_fns; /* interface function table */ |
83 | 83 | int cookie; /* implementation specific cookie */ |
84 | + char *name; /* device name in bitstream */ | |
84 | 85 | } Xilinx_desc; /* end, typedef Xilinx_desc */ |
85 | 86 | |
86 | 87 | /* Generic Xilinx Functions |
include/zynqpl.h
... | ... | @@ -45,16 +45,16 @@ |
45 | 45 | |
46 | 46 | /* Descriptor Macros */ |
47 | 47 | #define XILINX_XC7Z010_DESC(cookie) \ |
48 | -{ xilinx_zynq, devcfg, XILINX_XC7Z010_SIZE, NULL, cookie } | |
48 | +{ xilinx_zynq, devcfg, XILINX_XC7Z010_SIZE, NULL, cookie, "7z010" } | |
49 | 49 | |
50 | 50 | #define XILINX_XC7Z020_DESC(cookie) \ |
51 | -{ xilinx_zynq, devcfg, XILINX_XC7Z020_SIZE, NULL, cookie } | |
51 | +{ xilinx_zynq, devcfg, XILINX_XC7Z020_SIZE, NULL, cookie, "7z020" } | |
52 | 52 | |
53 | 53 | #define XILINX_XC7Z030_DESC(cookie) \ |
54 | -{ xilinx_zynq, devcfg, XILINX_XC7Z030_SIZE, NULL, cookie } | |
54 | +{ xilinx_zynq, devcfg, XILINX_XC7Z030_SIZE, NULL, cookie, "7z030" } | |
55 | 55 | |
56 | 56 | #define XILINX_XC7Z045_DESC(cookie) \ |
57 | -{ xilinx_zynq, devcfg, XILINX_XC7Z045_SIZE, NULL, cookie } | |
57 | +{ xilinx_zynq, devcfg, XILINX_XC7Z045_SIZE, NULL, cookie, "7z045" } | |
58 | 58 | |
59 | 59 | #endif /* _ZYNQPL_H_ */ |