From patchwork Mon Jan 2 18:26:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 638430 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp942500pvb; Mon, 2 Jan 2023 10:26:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXveNAvV5spNqv3d2XXqXEl9vD7AhFEA3nISLzX8T4tkhooExhWc5mUUc23iw2NDPXUpKB0F X-Received: by 2002:a05:6870:f815:b0:14f:a68c:7c76 with SMTP id fr21-20020a056870f81500b0014fa68c7c76mr19743321oab.42.1672683993113; Mon, 02 Jan 2023 10:26:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672683993; cv=none; d=google.com; s=arc-20160816; b=nC7bN8Aoah23vPy53yh/sGQTR0n+Xj9oZCfPWzj/XMaiymfefZDrdT7gNzC4EJJphG fesstQxxja7Rs0EXTC9DJUEjA29ozq+d3G/mAK+OCjJmpL9q2hbhWziIF+9uO0ABuIQR XFyyjRNDe3u/5G9D4PrhPTWdc9B9XvAXrNEtcsngKBL7itVX+ztHZXG1iN38uFNXqIqA GwtHYbk/AJwEjqo3sC6kgTmTS619P31yKgmKSVKd9xPYIlwepCqs27LDvL2CRfCxbOdo PWQMof7vz/Z5dlrixQ8xp+8QIvrMwvjtUjNHQJQ83asQ1oiyHmBdMYuVh+95BOYgezYD 3/cQ== 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=QVMIugrPy/4xs3AFxaVhthVJcc+ujfd6pP3K9vRKs84=; b=ESUlkxM3qwOmDmt9cjmParMJXDHCCWVZyHL35UsWJ8rqJ4GDouqUK45y7mFnTFzaVu AeN2CUX7uT8lzp1m6KPqN7koEwZjAQe3Kd5559fhnig+oYGVVKc8VOi8ynsjpWPqos9a +/5hGn2T4C6ln42TzkkLphZD992ck1dmSI3pwVGOU0JaAMypz0TM2NUWfh4u/0z2Z6Ev FYDEVzeHpps6JpgdYSu+OJ/rV/71Ecn9Atl3+tspPojPbS0J4rJGR67Q4khV+bAtLD8v oWXWl1/alXhZaKgTPv9NrrB3/kCXoZox1DPG4v0oHzt7ZsMLFf4QK2cIwXCS14P/OYXU r/AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gQwu34iA; 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 i20-20020a056870345400b001443ef47f6asi20287331oah.237.2023.01.02.10.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:26:33 -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=gQwu34iA; 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 1465A85413; Mon, 2 Jan 2023 19:26: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=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="gQwu34iA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BBC9285510; Mon, 2 Jan 2023 19:26:28 +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-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (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 0A8488533F for ; Mon, 2 Jan 2023 19:26: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-io1-xd32.google.com with SMTP id z126so4569254iof.13 for ; Mon, 02 Jan 2023 10:26:25 -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=QVMIugrPy/4xs3AFxaVhthVJcc+ujfd6pP3K9vRKs84=; b=gQwu34iAQD1T8D/dghWkLQfo+Brv3IqVFdUIHI9RVlNht/BDiUAknWHGLkJEzZYCVr RVzylREwIYQFR9oujiGM9HoiSR6xR59mxhcQNAGesArzgMtMFh2+xlFFo594ulkugZqq pMhTbEAKwH5WgnwIm2fN2zMZk3QPL2rs3vZX7PqYF693ji3W28bq2k1rk62TZ8WyFv6d yry5JlQrTKe/wjKvzAiQ20/veSeP3R2jnHEPMGjOVt2Z8FWAzgdL3J+pRr0oxJUw7w/Q CWaO04pm3uT+fMd2Tou9IUAqfGp2zFW+shUEwaEzea2CE3N2lyfaRMeJvt003Sn2PNSG SqSQ== 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=QVMIugrPy/4xs3AFxaVhthVJcc+ujfd6pP3K9vRKs84=; b=hTF5vIwHJdkrq5ZVzTFEmyfIU9uXoVEUy6MJI9r4gK5aPJE8uKm2BzVzgP0I3U3oUr UmispF5cRXdehfTm6hmRyk161u1pPupWuMXjlkBKYK96I5+6a5xXNOKf6S7IgB/Scus3 igKKCh1vEk9vSKB+tE8gy42ehj0JbNlUn3pvDr5gZxBuDTtzvkcSrad6zi0GZguNgLzw Q3gIMGk8VJGXWl7rkDrRuOKwGKBBiZoBkDtQydf4l2DWSbAOYhbYzPCHJTTPCo7sInqa Eg+8p9Z7Qi5xdOWEkyvMcbMaElbiO4+WdgBKjoySMsF5fUL8greoz0AdDemBLVa7nlDo HVWw== X-Gm-Message-State: AFqh2kqii9DyqvKFJnRXKwtZL3NYSM05XIJZKGLuAysepETSM9Fu8w0c 9sByCj7YZY2zD+oIIsZk0lFdl24AGb0= X-Received: by 2002:a6b:630b:0:b0:6df:e430:e8af with SMTP id p11-20020a6b630b000000b006dfe430e8afmr25861975iog.18.1672683984367; Mon, 02 Jan 2023 10:26:24 -0800 (PST) Received: from jassi-Alienware-x17-R2.. (wnpgmb0311w-ds01-45-179-115.dynamic.bellmts.net. [206.45.179.115]) by smtp.gmail.com with ESMTPSA id y4-20020a056602178400b006dfbe8b14cdsm10882820iox.8.2023.01.02.10.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:26:23 -0800 (PST) From: Jassi Brar X-Google-Original-From: Jassi Brar 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: [PATCHv3 1/5] fwu: gpt: use cached meta-data partition numbers Date: Mon, 2 Jan 2023 12:26:19 -0600 Message-Id: <20230102182619.2411192-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230102182532.2411125-1-jaswinder.singh@linaro.org> References: <20230102182532.2411125-1-jaswinder.singh@linaro.org> 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 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 Reviewed-by: Ilias Apalodimas --- 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,