From patchwork Fri Nov 4 02:42:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 621357 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp765502pvb; Thu, 3 Nov 2022 19:43:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5TwKF7A4Ag+jB4dD+2eCo+1r9WeLXb6axJ+PM0h3AW2KuaVyXufmzN8Psa3URV93pdgpGg X-Received: by 2002:aa7:d80a:0:b0:462:2c1c:8716 with SMTP id v10-20020aa7d80a000000b004622c1c8716mr34001369edq.185.1667529784616; Thu, 03 Nov 2022 19:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667529784; cv=none; d=google.com; s=arc-20160816; b=o8zqnqd6lf66CLE6Ad+2uJFwhHoAzWbLY6lBqrIWXir+A1iN2UxzT+9I+JEK9R+Oiq Fugh1V8Zbcw465DYYNAK//CURtxWL7P5sQvhcjclY8UJPIDngyShS7MOytOvXIf67/pA Xjt6H91MxEDhbyGRo5dPfPJnroriDFTU5SpcCEbT9JJyLegp2S/jHWuOcfvWK8eHKG2u uw6asZlDaklIdyvNY6/tUWBl9+MqeYCcxBKFJ1nfZuF54Bphs8zkk5hVvXcWwg5W+U/a L+8Ts+Ld54nAsCGfibVeGzL4CUbe+zv6D/BmvN44NRJ+B7Z7ORJS37k5pOVmR88k6UTT eHQA== 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=5FyUfIlxsOa0JR4F4PIjbYe3IlG212u5d1NnaVj/uq0=; b=not0EElpndtSD6ZYTJYEee5oLmzBQKafrm9a4B693AQkUnv2WscOCfpvdEvFH5rBc2 ksqDoYJN9ZNTgB7XUgPQYqMIww5jY+6jEfiTgPPLS8b/5EJloyofrkOHcY4p/3VFLtm0 Uk4pZTkzPE7D/VFJ2RoUQcxkX6nSrehyI2JZVHPLIrEM81qts4GLjhBbrGV1yasjp3t9 ld0OA//91c9KTB45j0LQz63rcDS4Hl8lRYJ3zzwnCfdWgMn4zreLUwTKHapXt96AgOoA uT9jkv/6QP/ZEXI7MHrqDIxYP/PwpdEJF6XLQygAlx9ygRllMg84Pb3tPpQ/iJ3NbXYc B16w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EFNXd+Oc; 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 hp32-20020a1709073e2000b00783645da4e5si3824426ejc.582.2022.11.03.19.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 19:43:04 -0700 (PDT) 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=EFNXd+Oc; 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 45DBA85156; Fri, 4 Nov 2022 03:43: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="EFNXd+Oc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9E67585101; Fri, 4 Nov 2022 03:42:59 +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-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (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 E778B84F99 for ; Fri, 4 Nov 2022 03:42:56 +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-xd35.google.com with SMTP id p184so2865981iof.11 for ; Thu, 03 Nov 2022 19:42:56 -0700 (PDT) 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=5FyUfIlxsOa0JR4F4PIjbYe3IlG212u5d1NnaVj/uq0=; b=EFNXd+OcA73luUaiNdV6pvHGkIykYR8XedQkf/cbKkjwM2V9YwiYdXrMJ/L0cxQgnG 6d29cdMXseRJjBgRREyqsm9hG/3aZSenjTxHOdsNL9u55ueUWQmoL45XMa8YIzj02QQu LgGfKwHZ2Og88+63YMdk4GC+zboncHZViR4Q3c3U5d/oMQFCRTvO4NdomkrU5tKS4tAo +gPcld9GgoZp6oGCMo3G6qv8uKasjjX7KlOI/tVMArqh5Nxn5rsfwD0e+0UvylW4mCWj a0gtp7DTuPWCLfEyX1rkIWlP6AdAwDZf6oZxq4Dj3N74x6/Nqt6E7rkKR36zmQHx6Z8c 6rPQ== 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=5FyUfIlxsOa0JR4F4PIjbYe3IlG212u5d1NnaVj/uq0=; b=d7d2miP4swX8nwa3wWjsrnmwfOlZCymsQuBXtvVgrUAGIIBbEllwK5DpaBIA6IOj/q W8Ocz/AnM3GZAjwmKHY4og3LUFx+68mliVmmvR5w/MtBn6GMvcjq7ee7Qrc7gFdlG0bZ MpIvKhEqQW2voEA0NrxuZ53Ec7QfJHZFE6TU2eqBKLs8zDmoV2o4EFqfZL+KojdscCpk 7SEBxEODtlplGjqCebpJ6Uyq+r377Fdjl2ttKRKjQIJCPUqku5ES1AKN1feIDZtW30+Y Wj1dZ+40tyFAtmq89zCKhUENMIMKdJONmPhKHh3MArtTGyOUn8R56NsBEiaRcM2PEbfH IQPw== X-Gm-Message-State: ACrzQf0KxQd1bepNMWlyua3qq0bkyOkDmtUhPojTiNt+QZk6DayhznRS X0MjMzfGKV7QaE7U+iWM3fzm2ImChuiJPA== X-Received: by 2002:a05:6638:40b:b0:375:55f7:f0ac with SMTP id q11-20020a056638040b00b0037555f7f0acmr17312219jap.249.1667529775134; Thu, 03 Nov 2022 19:42:55 -0700 (PDT) Received: from localhost.localdomain (wnpgmb0311w-ds01-45-179-115.dynamic.bellmts.net. [206.45.179.115]) by smtp.gmail.com with ESMTPSA id g9-20020a056602072900b006ccc36c963fsm1014265iox.43.2022.11.03.19.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 19:42:54 -0700 (PDT) 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 1/4] fwu: gpt: use cached meta-data partition numbers Date: Thu, 3 Nov 2022 21:42:50 -0500 Message-Id: <20221104024250.764728-1-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221104024217.764612-1-jassisinghbrar@gmail.com> References: <20221104024217.764612-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. Signed-off-by: Jassi Brar Acked-by: Etienne Carriere --- 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..d706e3d4e4 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}; + +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 partitons 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,