]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fpga: zynqpl: Add checking mechanism for binary format
authorMichal Simek <michal.simek@xilinx.com>
Wed, 3 Apr 2013 14:24:06 +0000 (16:24 +0200)
committerMichal Simek <michal.simek@xilinx.com>
Wed, 3 Apr 2013 14:24:06 +0000 (16:24 +0200)
It is common mistake that users are trying to load
bitstreams not in binary format to the zynq.

Also check bitstream size before load.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
drivers/fpga/zynqpl.c

index 17cccf94910167f0e764a22c84bb2448ae070692..6c455f4b5a2ed689db368f0230fd8498138bc593 100644 (file)
@@ -54,14 +54,46 @@ int zynq_info(Xilinx_desc *desc)
        return FPGA_SUCCESS;
 }
 
+/* Xilinx binary format header */
+const u32 bin_format[] = {
+       0xffffffff, /* Dummy words */
+       0xffffffff,
+       0xffffffff,
+       0xffffffff,
+       0xffffffff,
+       0xffffffff,
+       0xffffffff,
+       0xffffffff,
+       0x000000bb, /* Sync word */
+       0x11220044, /* Sync word */
+       0xffffffff,
+       0xffffffff,
+       0xaa995566, /* Sync word */
+};
+
 int zynq_load(Xilinx_desc *desc, const void *buf, size_t bsize)
 {
        unsigned long ts; /* Timestamp */
        u32 control;
        u32 isr_status;
        u32 status;
+       const u32 *test = buf;
+       int i;
+
+       /* Check bitstream size */
+       if (bsize != desc->size) {
+               printf("Error: File size is wrong - should be %x.\n",
+                                                               desc->size);
+               return FPGA_FAIL;
+       }
 
-       /* FIXME Add checking that passing bin is not a bitstream */
+       /* Checking that passing bin is not a bitstream */
+       for (i = 0; i < ARRAY_SIZE(bin_format); i++) {
+               if (test[i] != bin_format[i]) {
+                       puts("Error: File not in binary format.\n");
+                       return FPGA_FAIL;
+               }
+       }
 
        zynq_slcr_devcfg_disable();