From patchwork Sun Feb 5 03:01:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 650895 Delivered-To: patch@linaro.org Received: by 2002:a17:522:d8c:b0:4be:c3dc:14d8 with SMTP id d12csp1637053pva; Sat, 4 Feb 2023 19:01:47 -0800 (PST) X-Google-Smtp-Source: AK7set8SLKNdOKLgbRcotnyVikDHBMuOCm2IDeMUl0KlplG+5a4PaNKVt3OQjs2H4YhJY/Nq6HLg X-Received: by 2002:a05:6870:e0c6:b0:163:da10:a97a with SMTP id a6-20020a056870e0c600b00163da10a97amr7759742oab.26.1675566107606; Sat, 04 Feb 2023 19:01:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675566107; cv=none; d=google.com; s=arc-20160816; b=lLsPh1WJ8Y2dU1F2HifAi+BVI2YKkkxYn4OhFoq8+lCg4PxkbbyY39maedQNKUovlh cIMMyUoJgX8U5H4nOUDnA+td/qkwt91hihZ7ln1oiys6ncmJcg5/u0uVQwu9wdsjMSDU Dh8anr2S5aatqKwQX4Szcefpn3BjHdLDKN0APvm0T5YS8a4jBy/G1Xoziw460mUcfp+Z FtAFxQk+rrasW7fIbrS0R1UNeKskfwxTlSTHfOZW26sfh9SQwxmDgAlhnMnJ/Sko3Qvd ur2vzisLovy9AV03eDWdYT1r4Oy9ADXqUK6LCB7J4M245bULUx91gl41KKY4YFacEx7s mGow== 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=TLJpmbZip9U1/rQhc7eRRt+CMqKuSdB0ncBRBicC39yYHS7aRSf51wC3dZ775MDvse 9cFFtuAvU99jC5tFjbbw5LTpieJ1PnZ59IwbcnXMLj/k9eeGorRxWlb6Tyj3sCJMlFz8 uAKB87EvOBPo9H0RWwEr7ZVzKlx4Akmdv6LLvnu33LhhzQoUYbp7Wb+7AxKffqNybmHx 49PvL03dXLBqBdf9NHYrDQImU9lXZr5sSAlWm394H529iuvDrNZFiv54YVTtL/CDWjTK 2kfakD75rxFvF0lBQfU6F1SjY+nerz/wLizbQ9tZqNqy26OaksS7bVbrPgzhhLW28vQr LYag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QaLXRFzb; 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 q32-20020a056871082000b0016a0cf638e1si5394151oap.249.2023.02.04.19.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Feb 2023 19:01:47 -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=QaLXRFzb; 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 B92BF84517; Sun, 5 Feb 2023 04:01:45 +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="QaLXRFzb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0FE2D85748; Sun, 5 Feb 2023 04:01:43 +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-oo1-xc30.google.com (mail-oo1-xc30.google.com [IPv6:2607:f8b0:4864:20::c30]) (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 DBA8C844DA for ; Sun, 5 Feb 2023 04:01:38 +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-oo1-xc30.google.com with SMTP id y17-20020a4ade11000000b0051762fdf955so853562oot.3 for ; Sat, 04 Feb 2023 19:01:38 -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=QaLXRFzbDZnI6pCmoBPeM8Q3gyVpzXwjcavWENpaWnAMubUZL66sMBAeAvq0YkrdiH z0eF1kamyzNYyuOlc6GbY4JNp1Lv1d4zCfFhrcD9owKFFuYG7sJ5pxIHYS2wdpj5TCn3 zwMmGnZMo5/P8ODODepSFSNuH+rQHdhX/xGPrBio16ZD4kJ/+9HwivoGuf49fHF08Mgc SNdCR0eVveg0QiU9+4kRPs3OuX5XlQZRTwGwlTkygePbE0QvmcUe6f6UupqJslbiWDPh 4S6oaAeD0cA6Dxis6r2wg999+kFvI3W5Ax3Yb6qzobXcR72xg9MHdNlkH3LjKxD6gORF WjrQ== 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=WAgSmVdSgVmO98Vax3ycEjWaCmawkxEL+HKOgOEvu+JYJ4+V1sFWaUWuI3EhlrUSD3 w0fC6vLboaPDDfwxSilmOISyZeMvPtkY/ECp85WDF2bMSh99v896Ix02O6w2nHulGN9m k9jeAr6b/vdfvcbC63AzpdfJI3aCZ57SP8pND+dZyN93rO5aiW9ALqZZxMu+N/Q7CP8P Ps/w3Gl4iPA+wmvOmQvDsLNyfjMIo8YSkdQEmSu8VzPKIZbPpCjIiHmMBSdJxg7eey+f CMpt5rNQcKHzAVB3KHEOdP56pnvNNbNXOE0iSmyEFP1ME7z6+Sb17kAGeLX7VMXaTvcc RDbA== X-Gm-Message-State: AO0yUKU0jvoeMbMscxE4wMvVYIWHnKEkYfzys+aPfehOYI9SvaP1gc67 /50hvpagCJIpJrMxfpCapk4SV6IsDOs= X-Received: by 2002:a4a:a5cf:0:b0:511:fa8a:5846 with SMTP id k15-20020a4aa5cf000000b00511fa8a5846mr7134701oom.8.1675566097127; Sat, 04 Feb 2023 19:01:37 -0800 (PST) Received: from jassi-Alienware-x17-R2.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id c123-20020a4a0581000000b00511e01623bbsm2795709ooc.7.2023.02.04.19.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Feb 2023 19:01:36 -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: [PATCHv4 1/5] fwu: gpt: use cached meta-data partition numbers Date: Sat, 4 Feb 2023 21:01:31 -0600 Message-Id: <20230205030131.61402-1-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230205030056.61345-1-jassisinghbrar@gmail.com> References: <20230205030056.61345-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,