From 75f9994cd962249a9780b3695953e9c4a0a08dbb Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Wed, 3 Apr 2013 16:24:06 +0200 Subject: [PATCH] fpga: zynqpl: Add checking mechanism for binary format 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 --- drivers/fpga/zynqpl.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/fpga/zynqpl.c b/drivers/fpga/zynqpl.c index 17cccf94910..6c455f4b5a2 100644 --- a/drivers/fpga/zynqpl.c +++ b/drivers/fpga/zynqpl.c @@ -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(); -- 2.47.3