From patchwork Tue Feb 28 00:52:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 657466 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1b90:b0:222:2e2e:b2c3 with SMTP id e16csp3401736lty; Mon, 27 Feb 2023 16:52:44 -0800 (PST) X-Google-Smtp-Source: AK7set9Jhv1C40PATNO/33pU56qghiQJBbQn8PvxkBMbLkzddoKEbNuGrKRspHqlYbCrC1W/830c X-Received: by 2002:aa7:8f29:0:b0:5ac:41d5:ded2 with SMTP id y9-20020aa78f29000000b005ac41d5ded2mr891635pfr.1.1677545564589; Mon, 27 Feb 2023 16:52:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677545564; cv=none; d=google.com; s=arc-20160816; b=gvNATDKKBUusdWbhZZ9+js8QfpTAm7pcL1T8iNCezb2rLPDcglSjw0cjDPmRHnnekD XmjSLDe1Xs3m0TDgbW7OTDSj8EU5iSJ1mhDmItHBFmlWchNBWPpvlBwSk13G4tJJaFBi d2j0rBzXs1tANXXKus6i6kWuMqDmOv16S0Bfri0LyZL+hBpD/aNZQexR02aIhjgJL3Hc mTUtNewWDYIvTeYVmR3hgYx1XrB/Q/XYelsczSqZX1Doi99c8m/OrKPZpwoA7JED1wG6 CkaNEJdqda1kWimj6ZxueC0xrv1sIOQra1WDYaQXczl/rznnXQCFDE5KfaJ8tP01ScG3 aFQA== 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=wd1+HoHItjudv/YvEj8c+7vfyyXMP7QiTL/6vFQ95oE80iWrosVnRbpVpt2xx7yB1K 9/oLXG15GR88YyALFkU34T57Bf8V9inXOEqNToDFx6BVLYva3ekeMXJY7+pfr5eDSGlM sqR8+3p4X5GG7P1gW68cxAC0R1QilrHWIgKpIRq00lnydz5rWZtlf83hRFsPrdVeONy9 3CMFc8S3l+ChnmcVVFyDzWNhO8xiciDd8a5g7MQXZj4vwf/q9p21INLpJHCI+QFSeqoW ANl8DYVO4ydJUxSL6MiEXeh5OIlUQmtz1ud/faxjNCCwu20XvYnHWJCdTRjz+kafD2Rl VtEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=St5sVa3n; 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 h2-20020a056a00230200b005cd33628c0fsi9224853pfh.177.2023.02.27.16.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 16:52:44 -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=St5sVa3n; 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 9D49A85A9B; Tue, 28 Feb 2023 01:52:35 +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="St5sVa3n"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F2ADD85A9B; Tue, 28 Feb 2023 01:52:33 +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-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) (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 1588A85AB1 for ; Tue, 28 Feb 2023 01:52:31 +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-il1-x132.google.com with SMTP id u6so5392228ilk.12 for ; Mon, 27 Feb 2023 16:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=St5sVa3nqzMw9sWsBXReuV07/CvJgby+ILuDh6LuSEtsg5tk1qQ9bqqZ6lbFSxqhLf yEFNrjI6Zwpa4rztJkCw3xQaj8tJ2oFmVReielhVKmJzh82xlwHVtnhgbidy6WQ70Wt9 VXdSSxgIB+xaRt9qTUZ02jwjM2Hzk1MrTnsZDjF5nwbsTB6bZWkiV4FknsU0dQUSJmob MdytkLnOA4wqag5NutwB2NA5vh5CQeG8sA9SiMxCcXR+UqsQrXx0pkWQ31wMqsWUQqdR u51aw0N47s7ikm63tmjI4KE+JIyp4FU0dJ0wcMlsZcUfDEYO+QpY7zH2EPG9rLkeZVpM kAjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=dtatGR+Pqjn51Q2g2wHwXEtaC3JjUoPlgvo/cD2krW+PZl9u6xtKgQ7mwdNNMiGHPL jXoKnB8gQPsh3KCryo2+K3gcYz7oVH/A1SWPhBk+4I2ufF3iYDLSQk95zTWiogQhF0Gg gfpMgl45k1blxWHs97te6ijC9n3w9saRu9POq498VS5ZV25X2OBwTXKwTKl6BF32L+U0 swKXis0sCR/3lkhdoPcof9Sh9ACMVGSCdU98aXN/Be8aBRij1D2zGK0wrUHHY7odYG1e g984hFxXXEpCBzF96TfwZ27rsJLlwO+mA7kDePGEa2gj2S7pOuqmpmk/uf/IByWjJP6v 3+gA== X-Gm-Message-State: AO0yUKW4T2kKmMm5HwHSGUx2dt7azs6FPDhffsDvAUIwq+dHs7av0oOr stTTwaDm9MZrTpzRuD28PxUp1GSsqy4= X-Received: by 2002:a92:c269:0:b0:310:fa45:ac78 with SMTP id h9-20020a92c269000000b00310fa45ac78mr1013519ild.29.1677545550245; Mon, 27 Feb 2023 16:52:30 -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 r10-20020a02c6ca000000b003acde48bdc3sm2436517jan.111.2023.02.27.16.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 16:52:29 -0800 (PST) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de Cc: ilias.apalodimas@linaro.org, etienne.carriere@linaro.org, trini@konsulko.com, sjg@chromium.org, sughosh.ganu@linaro.org, xypron.glpk@gmx.de, patrick.delaunay@foss.st.com, patrice.chotard@foss.st.com, Jassi Brar Subject: [PATCH v5 2/6] fwu: gpt: use cached meta-data partition numbers Date: Mon, 27 Feb 2023 18:52:27 -0600 Message-Id: <20230228005227.1635803-1-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230228005135.1635726-1-jassisinghbrar@gmail.com> References: <20230228005135.1635726-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.6 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,