]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fpga: zynqmp: add bitstream compatible checking
authorOleksandr Suvorov <oleksandr.suvorov@foundries.io>
Fri, 22 Jul 2022 14:16:12 +0000 (17:16 +0300)
committerMichal Simek <michal.simek@amd.com>
Tue, 26 Jul 2022 07:34:21 +0000 (09:34 +0200)
Check whether the FPGA ZynqMP driver supports the given bitstream
image type.

Signed-off-by: Oleksandr Suvorov <oleksandr.suvorov@foundries.io>
Tested-by: Ricardo Salveti <ricardo@foundries.io>
Tested-by: Adrian Fiergolski <adrian.fiergolski@fastree3d.com>
Link: https://lore.kernel.org/r/20220722141614.297383-12-oleksandr.suvorov@foundries.io
Signed-off-by: Michal Simek <michal.simek@amd.com>
drivers/fpga/zynqmppl.c

index 2791f931861c70a93cde7d083d8a7c04b25169a1..feaf34fff119e8fc5f7235c93f149949fb73bb55 100644 (file)
@@ -199,6 +199,28 @@ static int zynqmp_validate_bitstream(xilinx_desc *desc, const void *buf,
        return 0;
 }
 
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+static int zynqmp_check_compatible(xilinx_desc *desc, int flags)
+{
+       /* If no flags set, the image is legacy */
+       if (!flags)
+               return 0;
+
+       /* For legacy bitstream images no need for other methods exist */
+       if ((flags & desc->flags) && flags == FPGA_LEGACY)
+               return 0;
+
+       /*
+        * Other images are handled in secure callback loads(). Check
+        * callback existence besides image type support.
+        */
+       if (desc->operations->loads && (flags & desc->flags))
+               return 0;
+
+       return FPGA_FAIL;
+}
+#endif
+
 static int zynqmp_load(xilinx_desc *desc, const void *buf, size_t bsize,
                     bitstream_type bstype, int flags)
 {
@@ -210,6 +232,18 @@ static int zynqmp_load(xilinx_desc *desc, const void *buf, size_t bsize,
        u32 bsize_req = (u32)bsize;
        u32 ret_payload[PAYLOAD_ARG_CNT];
 
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+       ret = zynqmp_check_compatible(desc, flags);
+       if (ret) {
+               if (ret != -ENODATA) {
+                       puts("Missing loads() operation or unsupported bitstream type\n");
+                       return FPGA_FAIL;
+               }
+               /* If flags is not set, the image treats as legacy */
+               flags = FPGA_LEGACY;
+       }
+#endif
+
        if (zynqmp_firmware_version() <= PMUFW_V1_0) {
                puts("WARN: PMUFW v1.0 or less is detected\n");
                puts("WARN: Not all bitstream formats are supported\n");