From patchwork Sat Dec 3 03:16:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 630639 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp1309406pvb; Fri, 2 Dec 2022 19:17:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf4UdBmc8xvAjS2uy8Q6Q03qlj4d+LtQo1N+aY+47XBeZjNYTwIADvrzd2mf0xV6EoX1tpke X-Received: by 2002:a6b:7006:0:b0:6df:e590:5d4 with SMTP id l6-20020a6b7006000000b006dfe59005d4mr3476859ioc.132.1670037426695; Fri, 02 Dec 2022 19:17:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670037426; cv=none; d=google.com; s=arc-20160816; b=kdaEt0T+v9l2TFGFC4wRm9JTFM9//MB7Vf67nndL1/iWywtq7c6S0ZuuzdEWGRYZpz 0qmi/Rt4BLQoecUbbPHltBNpZczOsJPek6OX+YXd6Dlo9sCQ07b0qgfpqYw8oAB0PB7K vUid9Rc8z+zMBoJNCHiZInwlCiglIX064rvOo9fi0KjpR85XQBOwyYSuXYEA2J6AlvtW KHp6P5R3Q8VsX128sf+g2JB0JIivvaoXLF1fwb+nfXrTsQUfrYSnjIIYjV6ZBbWUI6OL mSPNuIBewqjXE0E1TsEvic3dME2AD0ouhLNZ7IzGWZ3VMXO8wr3kAaQJmyZORJkW+JZt Ebeg== 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=65Pjm5oEjAmp6DR8n2ENI+bPG3ZyHqPwadlAz4GLtiE=; b=F49Psl21WACrDdiOk1frGQOFLDAGe5Mad5CpJ5gI0P+d5Z85IwPnolgbrhs6noREG7 dUp8AXMV5DbBz7zaSiGCGqnop6CQ6h8gnZ73aHCLBWpr6ceRKO25H4pMljbfQ+Bvinjm 3aK5FF34Cw95Gfd4U0dYKf5RZJdjKSxpk1b2JPSjbi8cmso6ctMJPFgGZow3fjo2ewlt TqhFGIKZtC6QToDfm0k/+LHveW2NVmIciuPY5r2NQKnMUD2trb4qYuH0ABVfEWwDPn/e fCHvMbvVIbtHWCsVVV7tNqtRMZGj1fUbPggoLnrZq/ZxqsNpYOnJI4Sn5Epm8g0+DJ/r HhtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=biD7orcQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id s17-20020a02ad11000000b0038a338a303bsi341963jan.78.2022.12.02.19.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 19:17:06 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=biD7orcQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 DA55085023; Sat, 3 Dec 2022 04:17:02 +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="biD7orcQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C6E3C84FF0; Sat, 3 Dec 2022 04:17:00 +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-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) (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 9BBA785023 for ; Sat, 3 Dec 2022 04:16:57 +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-x134.google.com with SMTP id h15so2861465ilh.12 for ; Fri, 02 Dec 2022 19:16:57 -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=65Pjm5oEjAmp6DR8n2ENI+bPG3ZyHqPwadlAz4GLtiE=; b=biD7orcQExuzagDIhc8JSV6Q9eqcWb/YdSzJBJ+o10BaWSJhOcypmaZ+LqzpYbxboh cNrpkvIzTnn6+mPSjWk49iA0nW7MFUtO6V92ltBmoyXCsC1Qc3j5iNQSRt9GFwvnKGDz XAlOd5AbqwB86jd+7Cwd54xB/t0FY5H3R4pPni7wRMM7uMI30vSO67IHuYDIiOs+5sI5 XaLlRAdJEzfRoqP6qAy6Y826Mp2g5l3HX2Qv0tVfwWqUxrqvtC7TJDiSMazMEq4B1QM6 STl8TycmdDx5KuzsKchZvNEjAjEzXtMFB5O1EkV9SGeM+rwsAxKyrGO3B9K98oGGEovc gqeQ== 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=65Pjm5oEjAmp6DR8n2ENI+bPG3ZyHqPwadlAz4GLtiE=; b=SPHsT9ZCcM3DNzD7AQxz02N2ZVDVWgybvgaYmjnHCdiDws/q9zhBfN7NIaJhAvaJnp r3MR2YBhKMWbRTmJf0LG0TcA/X8T1mvSD1lu8cze8Azj4eBTTfeN8bafZ3kFSb2nNx1I IWQZ2nkMQihYcmQQrQ8cClAYnLlFkz9s/6qrC2NAWqsfyEjtnu4L0rw874lSwoWNFa1i 0IEWxQnwifz6Q059YW1JvEZ5HauS0zV/lqjzhSEVPITqyVKMXHnGo+2lW8hIYJjHD9Zn hq5d5A8yI+SbzHfRgQuPAzNHL0FxQWicVw3sUVrn+YpRX9UaOUYTj0Q54MkSwzBMPU3d DUbg== X-Gm-Message-State: ANoB5pnQIsWlezJVo8rP4ShWbeSqSwjwKSZytSd6AwZuACgfDA7q1Ij7 iyiIjUxG8gPFrg6rK5D+AjAKj5zW9nw= X-Received: by 2002:a92:1903:0:b0:2ea:e57a:e589 with SMTP id 3-20020a921903000000b002eae57ae589mr27045249ilz.240.1670037415752; Fri, 02 Dec 2022 19:16:55 -0800 (PST) Received: from jassi-desktop.. (wnpgmb0311w-ds01-45-179-115.dynamic.bellmts.net. [206.45.179.115]) by smtp.gmail.com with ESMTPSA id m36-20020a026a64000000b00389be83f294sm3201645jaf.133.2022.12.02.19.16.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 19:16:55 -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: [PATCHv2 1/4] fwu: gpt: use cached meta-data partition numbers Date: Fri, 2 Dec 2022 21:16:51 -0600 Message-Id: <20221203031651.579771-1-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221203031557.579632-1-jassisinghbrar@gmail.com> References: <20221203031557.579632-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 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,