All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr Suvorov <oleksandr.suvorov@foundries.io>
To: u-boot@lists.denx.de
Cc: Michal Simek <michal.simek@xilinx.com>,
	Adrian Fiergolski <adrian.fiergolski@fastree3d.com>,
	Ricardo Salveti <ricardo@foundries.io>,
	Jorge Ramirez-Ortiz <jorge@foundries.io>,
	Igor Opaniuk <igor.opaniuk@foundries.io>,
	Oleksandr Suvorov <oleksandr.suvorov@foundries.io>,
	Michal Simek <michal.simek@amd.com>
Subject: [PATCH v12 11/13] fpga: zynqmp: add bitstream compatible checking
Date: Fri, 22 Jul 2022 17:16:12 +0300	[thread overview]
Message-ID: <20220722141614.297383-12-oleksandr.suvorov@foundries.io> (raw)
In-Reply-To: <20220722141614.297383-11-oleksandr.suvorov@foundries.io>

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>
---

Changes in v12:
- exclude all secure-related code if FPGA_LOAD_SECURE is disabled

Changes in v10:
- fix grammar

 drivers/fpga/zynqmppl.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/fpga/zynqmppl.c b/drivers/fpga/zynqmppl.c
index 2791f931861..feaf34fff11 100644
--- a/drivers/fpga/zynqmppl.c
+++ b/drivers/fpga/zynqmppl.c
@@ -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");
-- 
2.36.1


  reply	other threads:[~2022-07-22 14:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22 14:16 [PATCH v12 00/13] fpga: zynqmp: Adding support of loading authenticated images Oleksandr Suvorov
2022-07-22 14:16 ` [PATCH v12 01/13] fpga: add option for loading FPGA secure bitstreams Oleksandr Suvorov
2022-07-22 14:16   ` [PATCH v12 02/13] fpga: xilinx: add missed identifier names Oleksandr Suvorov
2022-07-22 14:16     ` [PATCH v12 03/13] fpga: xilinx: add bitstream flags to driver desc Oleksandr Suvorov
2022-07-22 14:16       ` [PATCH v12 04/13] fpga: zynqmp: add str2flags call Oleksandr Suvorov
2022-07-22 14:16         ` [PATCH v12 05/13] fpga: xilinx: pass compatible flags to xilinx_load() Oleksandr Suvorov
2022-07-22 14:16           ` [PATCH v12 06/13] fpga: pass compatible flags to fpga_load() Oleksandr Suvorov
2022-07-22 14:16             ` [PATCH v12 07/13] fpga: add fpga_compatible2flag Oleksandr Suvorov
2022-07-22 14:16               ` [PATCH v12 08/13] spl: fit: pass real compatible flags to fpga_load() Oleksandr Suvorov
2022-07-22 14:16                 ` [PATCH v12 09/13] fpga: xilinx: pass compatible flags to load() callback Oleksandr Suvorov
2022-07-22 14:16                   ` [PATCH v12 10/13] fpga: zynqmp: reduce zynqmppl_load() code Oleksandr Suvorov
2022-07-22 14:16                     ` Oleksandr Suvorov [this message]
2022-07-22 14:16                       ` [PATCH v12 12/13] fpga: zynqmp: support loading authenticated images Oleksandr Suvorov
2022-07-22 14:16                         ` [PATCH v12 13/13] fpga: zynqmp: support loading encrypted bitfiles Oleksandr Suvorov
2022-07-26  7:32                         ` [PATCH v12 12/13] fpga: zynqmp: support loading authenticated images Michal Simek
2022-07-26  7:32 ` [PATCH v12 00/13] fpga: zynqmp: Adding support of " Michal Simek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220722141614.297383-12-oleksandr.suvorov@foundries.io \
    --to=oleksandr.suvorov@foundries.io \
    --cc=adrian.fiergolski@fastree3d.com \
    --cc=igor.opaniuk@foundries.io \
    --cc=jorge@foundries.io \
    --cc=michal.simek@amd.com \
    --cc=michal.simek@xilinx.com \
    --cc=ricardo@foundries.io \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.