From patchwork Mon Mar 6 23:18:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 659271 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp2085201wrb; Mon, 6 Mar 2023 15:18:43 -0800 (PST) X-Google-Smtp-Source: AK7set9pRLOT9Crn7kzI4OJX9Ow9rLmXjBVOBB/H+Z38WRxNf5fh7hpICWtRfS4IwLYquw3Cz4dv X-Received: by 2002:a05:600c:348d:b0:3eb:9822:2907 with SMTP id a13-20020a05600c348d00b003eb98222907mr7613257wmq.4.1678144723306; Mon, 06 Mar 2023 15:18:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678144723; cv=none; d=google.com; s=arc-20160816; b=NAN+kicMFakuL4A+1eu8OfEEM5zvAKI3CDYvmeEuK0lnamByCWqcwM7R+ie8KPD8or LP0/h0TwV+fYhJNdtKH/HUfx2lxaLX6lYzUCLGk2V7RkUmSm1RhVsxPyBOCjDPPIXotm F9PXB40RgWsGFbB6nDHV6fhjcix9zYZS7QcVNdzAG6giN/YJHT5tgfi+IXmhWNV9D5FH MQ/if433HMCkJG8QPL5rD4s5+dkzHiXBjUJh+BOpX6wDxpsUlTY01cC66tNpdO7gw6hO vR71m7991k1XcIkRN3gr+yF7R3P9IqtB+W+hSwDELE2zzI8P2FKnYKTS0qIpVZmOVW9I dxSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OqrEJod3ivHJIndjxZEF04GLcVg2nalUNAkbYgXe5hM=; b=UUP6jyAyqxq0wsU1JnDRucGX3G/eFqw5M3TkGap/0ZbzRNZlac4ss3tEEMky8nwk/+ SkxJDJAwMrGRmTqIt4Dj1PTLu3hPDjbpg9yhqbuJ9Kk2ipluQpJjkkt24s9BVqpgNH8e rZHr8N/3itGcOJamIncw37Lo11ffqx1br3S3OSetgvIy/NSync/vyk0FJF50fWKDOcRW 2Li6DBIoUWRlOP9rbnVyP7ZPssbJLlbc1tBhxQU5JJPEdCZc74hyK5F0CXbGoClVDFbD SttAp3DVQzZWS+NtNI1PeJsQhFdvFJ7gKOZQ9Bu/GL0Byj5TB+wzDPEFRJXu/rCPzlD9 AFMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oBanZdf4; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id o15-20020a05600c4fcf00b003eb546278c9si9546868wmq.160.2023.03.06.15.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 15:18:43 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oBanZdf4; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B1BB485A72; Tue, 7 Mar 2023 00:18:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oBanZdf4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EE9C485906; Tue, 7 Mar 2023 00:18:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AFC9A859E1 for ; Tue, 7 Mar 2023 00:18:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-qt1-x82f.google.com with SMTP id l13so12623184qtv.3 for ; Mon, 06 Mar 2023 15:18:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678144705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OqrEJod3ivHJIndjxZEF04GLcVg2nalUNAkbYgXe5hM=; b=oBanZdf4BU/zwjCQPy7zZ+dEoeXJBpQbifkdkD50Faz5hjqsW9RonKXM29LFPSLU9v Y+IiU5c5Z1gw/f1GwL9LJeZl5UR077A7xNCaDyEv59zCVMo4yiFi1h0wiBf88NYDKwWc sP7Kzk3TrYgdx2cnguMFBNfGrq5U158PmCIOM6O/YVtb2fRQXxv6UaDBkA4pZ39vdSpS ViJXQZ4TTkP5ezHKYiVu+eWFdZHwWX8/ZTF/YysAQrEbjteodAcoPGST2YPcjBjEnq5f fURVsos/7358Y3x1UnATQoxJIRVJZlto8jkuuZUmaLmguk/2EVA7EG6HcrEi114+UBoo sxJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678144705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OqrEJod3ivHJIndjxZEF04GLcVg2nalUNAkbYgXe5hM=; b=SxWVs9OCxmpQhZM8EJnxsyKPW7da/mQ+Vh/MquXuIQAF10EZKuXHaL2Hx3tVe4C0Hx s75DGLmj8+q34XPp/9b5+2yhKerXzSGjodaCds3Oaf1Uf25sGZCoZANXn4vDu0zjTU1g J/ezdXcOU0XzppTDdkhmbQnXAwwhij2V6dCM5cp28Z1po5WSOn0fM4f0T75oYJ/z73i/ tZmmK0SBjeICmJCWhQVUFohN//KfTTLVcxRQxkfu4KBN6e6e6ZnSj+eiib32HpE2Oklj IDjxrr4JOZbSFcJ3aOuuhWvNhqn9aLC2nvOiquflxPwcYyJDUW9nD0gn1KqYrJVVIE1j AC6w== X-Gm-Message-State: AO0yUKVKErZiZtgSsT9VMysSLEBXj0jLGe9mW+O6y5cR7blL9sH/qKsy omB6IqEZoDffG1d6eEcAkC21ycvZ5Vs= X-Received: by 2002:a05:622a:2cc:b0:3bf:b8ae:fa7d with SMTP id a12-20020a05622a02cc00b003bfb8aefa7dmr21653732qtx.55.1678144705163; Mon, 06 Mar 2023 15:18:25 -0800 (PST) Received: from jassi-desktop.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id e15-20020ac85dcf000000b003bfad864e81sm8522512qtx.69.2023.03.06.15.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 15:18:24 -0800 (PST) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de Cc: ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, etienne.carriere@linaro.org, trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, patrick.delaunay@foss.st.com, patrice.chotard@foss.st.com, Jassi Brar Subject: [PATCH v6 2/7] fwu: gpt: use cached meta-data partition numbers Date: Mon, 6 Mar 2023 17:18:21 -0600 Message-Id: <20230306231821.1888564-1-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306231747.1888513-1-jassisinghbrar@gmail.com> References: <20230306231747.1888513-1-jassisinghbrar@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Jassi Brar Use cached values and avoid parsing and scanning through partitions everytime for meta-data partitions because they can't change after bootup. Acked-by: Etienne Carriere Reviewed-by: Ilias Apalodimas Signed-off-by: Jassi Brar --- drivers/fwu-mdata/gpt_blk.c | 43 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/drivers/fwu-mdata/gpt_blk.c b/drivers/fwu-mdata/gpt_blk.c index d35ce49c5c..28f5d23e1e 100644 --- a/drivers/fwu-mdata/gpt_blk.c +++ b/drivers/fwu-mdata/gpt_blk.c @@ -24,8 +24,9 @@ enum { MDATA_WRITE, }; -static int gpt_get_mdata_partitions(struct blk_desc *desc, - uint mdata_parts[2]) +static uint g_mdata_part[2]; /* = {0, 0} to check against uninit parts */ + +static int gpt_get_mdata_partitions(struct blk_desc *desc) { int i, ret; u32 nparts; @@ -33,18 +34,19 @@ static int gpt_get_mdata_partitions(struct blk_desc *desc, struct disk_partition info; const efi_guid_t fwu_mdata_guid = FWU_MDATA_GUID; + /* if primary and secondary partitions already found */ + if (g_mdata_part[0] && g_mdata_part[1]) + return 0; + nparts = 0; - for (i = 1; i < MAX_SEARCH_PARTITIONS; i++) { + for (i = 1; i < MAX_SEARCH_PARTITIONS && nparts < 2; i++) { if (part_get_info(desc, i, &info)) continue; uuid_str_to_bin(info.type_guid, part_type_guid.b, UUID_STR_FORMAT_GUID); - if (!guidcmp(&fwu_mdata_guid, &part_type_guid)) { - if (nparts < 2) - mdata_parts[nparts] = i; - ++nparts; - } + if (!guidcmp(&fwu_mdata_guid, &part_type_guid)) + g_mdata_part[nparts++] = i; } if (nparts != 2) { @@ -127,26 +129,25 @@ static int fwu_gpt_update_mdata(struct udevice *dev, struct fwu_mdata *mdata) { int ret; struct blk_desc *desc; - uint mdata_parts[2]; struct fwu_mdata_gpt_blk_priv *priv = dev_get_priv(dev); desc = dev_get_uclass_plat(priv->blk_dev); - ret = gpt_get_mdata_partitions(desc, mdata_parts); + ret = gpt_get_mdata_partitions(desc); if (ret < 0) { log_debug("Error getting the FWU metadata partitions\n"); return -ENOENT; } /* First write the primary partition */ - ret = gpt_read_write_mdata(desc, mdata, MDATA_WRITE, mdata_parts[0]); + ret = gpt_read_write_mdata(desc, mdata, MDATA_WRITE, g_mdata_part[0]); if (ret < 0) { log_debug("Updating primary FWU metadata partition failed\n"); return ret; } /* And now the replica */ - ret = gpt_read_write_mdata(desc, mdata, MDATA_WRITE, mdata_parts[1]); + ret = gpt_read_write_mdata(desc, mdata, MDATA_WRITE, g_mdata_part[1]); if (ret < 0) { log_debug("Updating secondary FWU metadata partition failed\n"); return ret; @@ -158,16 +159,14 @@ static int fwu_gpt_update_mdata(struct udevice *dev, struct fwu_mdata *mdata) static int gpt_get_mdata(struct blk_desc *desc, struct fwu_mdata *mdata) { int ret; - uint mdata_parts[2]; - - ret = gpt_get_mdata_partitions(desc, mdata_parts); + ret = gpt_get_mdata_partitions(desc); if (ret < 0) { log_debug("Error getting the FWU metadata partitions\n"); return -ENOENT; } - ret = gpt_read_write_mdata(desc, mdata, MDATA_READ, mdata_parts[0]); + ret = gpt_read_write_mdata(desc, mdata, MDATA_READ, g_mdata_part[0]); if (ret < 0) { log_debug("Failed to read the FWU metadata from the device\n"); return -EIO; @@ -182,7 +181,7 @@ static int gpt_get_mdata(struct blk_desc *desc, struct fwu_mdata *mdata) * Try to read the replica. */ memset(mdata, '\0', sizeof(struct fwu_mdata)); - ret = gpt_read_write_mdata(desc, mdata, MDATA_READ, mdata_parts[1]); + ret = gpt_read_write_mdata(desc, mdata, MDATA_READ, g_mdata_part[1]); if (ret < 0) { log_debug("Failed to read the FWU metadata from the device\n"); return -EIO; @@ -206,9 +205,15 @@ static int fwu_gpt_get_mdata(struct udevice *dev, struct fwu_mdata *mdata) static int fwu_gpt_get_mdata_partitions(struct udevice *dev, uint *mdata_parts) { struct fwu_mdata_gpt_blk_priv *priv = dev_get_priv(dev); + int err; + + err = gpt_get_mdata_partitions(dev_get_uclass_plat(priv->blk_dev)); + if (!err) { + mdata_parts[0] = g_mdata_part[0]; + mdata_parts[1] = g_mdata_part[1]; + } - return gpt_get_mdata_partitions(dev_get_uclass_plat(priv->blk_dev), - mdata_parts); + return err; } static int fwu_gpt_read_mdata_partition(struct udevice *dev,