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, From patchwork Mon Jan 2 18:26:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 638431 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp942598pvb; Mon, 2 Jan 2023 10:26:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXsi4Kz0MCjqrnZtUD+oxTxy0h5yWreY7VA2KFcZL2qVFKci4xn0uAx3GVsji1FxW6naraFJ X-Received: by 2002:a05:6808:1509:b0:35e:373e:2d92 with SMTP id u9-20020a056808150900b0035e373e2d92mr25553877oiw.18.1672684012261; Mon, 02 Jan 2023 10:26:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672684012; cv=none; d=google.com; s=arc-20160816; b=GLHRfEvacIC0+aLxCeod/7B4FGZPbfMJLZ+0WieC1sTPHDgsVhhKLQhZ5HoBLayK3l 4vZektS47QxOUN+AbOr4RGwaytOeBxHT+aqCTMt4P5GJaJZ9psE38UqG515FH/gxwsix pqPbfHOhSZn78YDqfdKA28ZJ5Y+ofrYRp75Sm91+LMg+OkdxXK5aNLgR78054NBZ8Ooe re2bMrgZaeR8qcXYGnrDHVbizRHA4YkBOvvZ8JWkpa+hzKJYPSwobi+lTDZRt35gIdyq Ir5f3Um4lLSEDGJYftOD4TBElSU16RWsmrI3L7gHUPlBHgNJfnmUDC3cvx+5754T4YuF lhdQ== 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=0LKMUfr/i3qfi9TBhajPxC6GYt3klbg+iA1JR+CJGnM=; b=Lwfl9bTqq6QDoQuvOkNuw2+pc4cJ4uSKvOyelHVNW0rsznxj/5OV0a0y/MWQc9Ad7r uWO5ESpPvJUz/Z/TL/2Dj9z3YmCviAz4YY1dKWxXNCDetYD+WLavCEtqSZoTO0REMDci FktWxbP850xOgt1rl1NkvIGhXobOMj3HdzisMz/wKoSvHWQjqj8u6dnMDn84h6DhpI3N qLi31WAKgX0MM3kNxEkyTcR5MbwpvTmc9uybMkA+7XIiqqbYK4xB8HLUHqYsMuFJM5/q laRSdicgHKYpBFJu6FlzYdl+3uOupTw9ShVPZS0DVEbI6sqrCrvubOFUZjQiL4HjIrGz 6eCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NuIIOH12; 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 bf12-20020a056808190c00b0035a79445caasi23663391oib.156.2023.01.02.10.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:26:52 -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=NuIIOH12; 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 8BB8F8551B; Mon, 2 Jan 2023 19:26:50 +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="NuIIOH12"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3068485521; Mon, 2 Jan 2023 19:26:49 +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-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) (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 2AC578533F for ; Mon, 2 Jan 2023 19:26:46 +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-x12d.google.com with SMTP id c20so13060808ilj.10 for ; Mon, 02 Jan 2023 10:26:46 -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=0LKMUfr/i3qfi9TBhajPxC6GYt3klbg+iA1JR+CJGnM=; b=NuIIOH123YXBkeF2DPJUmC3OIZnPSZXfwOAUMguD/lnnJsylo9KHgEfuOc85tDHYTb 81ufLiUQHbZ9Z1iZN8tTMAVEPAa2vS1Y8rxT/4CYopfAy0o1nu6ATdqhtW2xAECoIRAO cme6/GXdeYF5XjvIyX3g21zquuGoWoYm2F2wLan8rN5rd0ppdJSunST6zucFCbLNNCrb 91O+WYysYUe4jkgVHRyXvUYth5Ow2ywWO9b0iAITA0/O3EO7FUSTElvqifSHle+7+75n 8i1gIdhIClc0Ym0VOZj5SokhZKf8svPVydjEf+3BC1hIVgf3Vf+Us3MITNq0Pw2bVBCE nR8A== 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=0LKMUfr/i3qfi9TBhajPxC6GYt3klbg+iA1JR+CJGnM=; b=mBRLTFanMk4HdnUlzBTM7mEav35e9WQFUdUjymUp4N/90IgEDYF9ma6VfWE9mXP8Pk F6F3BuYwvU10IqLDe6mPEgL5TT1cc2IWrPAm0+VI2n4PPjHm4qbxXdTW0alliuv0Far1 OstTLltPLLi3e4iu7g6pjtv3wp6L7T9q1jQ6FnPLJB3OyUgu3E8R5TpqYpQcOpYswCwa oxtPe9Ci8ox69+4waxPVq4Hx0UjJEtAqf4dkXdgJN265I1XoLC31U1hZCuM7R8Xeez7j W0qZMjT5YRXaJY2vj4K/bxN0bArpL32l2p6ckRp/9UV1AJ0LGYzd4yDcmZYZjtfsmkmj rn+w== X-Gm-Message-State: AFqh2kqMlGJa917+mOH2VgFRtQSng/hGk1i7fq/ErIzUDG/6hblDtQe+ aG1o1zMAw/7lWuDp+Tl66ZMtuqU92Bk= X-Received: by 2002:a92:6b03:0:b0:303:8cff:983b with SMTP id g3-20020a926b03000000b003038cff983bmr27846658ilc.14.1672684004440; Mon, 02 Jan 2023 10:26:44 -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 q17-20020a02b051000000b00389dbc74fc5sm9170654jah.78.2023.01.02.10.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:26:44 -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 2/5] fwu: move meta-data management in core Date: Mon, 2 Jan 2023 12:26:40 -0600 Message-Id: <20230102182640.2411224-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 Instead of each i/f having to implement their own meta-data verification and storage, move the logic in common code. This simplifies the i/f code much simpler and compact. Signed-off-by: Jassi Brar --- drivers/fwu-mdata/fwu-mdata-uclass.c | 34 +++++++ include/fwu.h | 41 ++++++++ lib/fwu_updates/fwu.c | 142 ++++++++++++++++++++++++++- 3 files changed, 213 insertions(+), 4 deletions(-) diff --git a/drivers/fwu-mdata/fwu-mdata-uclass.c b/drivers/fwu-mdata/fwu-mdata-uclass.c index b477e9603f..e03773c584 100644 --- a/drivers/fwu-mdata/fwu-mdata-uclass.c +++ b/drivers/fwu-mdata/fwu-mdata-uclass.c @@ -16,6 +16,40 @@ #include #include +/** + * fwu_read_mdata() - Wrapper around fwu_mdata_ops.read_mdata() + * + * Return: 0 if OK, -ve on error + */ +int fwu_read_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary) +{ + const struct fwu_mdata_ops *ops = device_get_ops(dev); + + if (!ops->read_mdata) { + log_debug("read_mdata() method not defined\n"); + return -ENOSYS; + } + + return ops->read_mdata(dev, mdata, primary); +} + +/** + * fwu_write_mdata() - Wrapper around fwu_mdata_ops.write_mdata() + * + * Return: 0 if OK, -ve on error + */ +int fwu_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary) +{ + const struct fwu_mdata_ops *ops = device_get_ops(dev); + + if (!ops->write_mdata) { + log_debug("write_mdata() method not defined\n"); + return -ENOSYS; + } + + return ops->write_mdata(dev, mdata, primary); +} + /** * fwu_get_mdata_part_num() - Get the FWU metadata partition numbers * @dev: FWU metadata device diff --git a/include/fwu.h b/include/fwu.h index 0919ced812..1a700c9e6a 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -24,6 +24,26 @@ struct fwu_mdata_gpt_blk_priv { * @update_mdata() - Update the FWU metadata copy */ struct fwu_mdata_ops { + /** + * read_mdata() - Populate the asked FWU metadata copy + * @dev: FWU metadata device + * @mdata: Copy of the FWU metadata + * @primary: If primary or secondary copy of meta-data is to be read + * + * Return: 0 if OK, -ve on error + */ + int (*read_mdata)(struct udevice *dev, struct fwu_mdata *mdata, bool primary); + + /** + * write_mdata() - Write the given FWU metadata copy + * @dev: FWU metadata device + * @mdata: Copy of the FWU metadata + * @primary: If primary or secondary copy of meta-data is to be written + * + * Return: 0 if OK, -ve on error + */ + int (*write_mdata)(struct udevice *dev, struct fwu_mdata *mdata, bool primary); + /** * check_mdata() - Check if the FWU metadata is valid * @dev: FWU device @@ -126,6 +146,27 @@ struct fwu_mdata_ops { EFI_GUID(0x0c996046, 0xbcc0, 0x4d04, 0x85, 0xec, \ 0xe1, 0xfc, 0xed, 0xf1, 0xc6, 0xf8) +/** + * fwu_read_mdata() - Wrapper around fwu_mdata_ops.read_mdata() + */ +int fwu_read_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary); + +/** + * fwu_write_mdata() - Wrapper around fwu_mdata_ops.write_mdata() + */ +int fwu_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary); + +/** + * fwu_get_verified_mdata() - Read, verify and return the FWU metadata + * + * Read both the metadata copies from the storage media, verify their checksum, + * and ascertain that both copies match. If one of the copies has gone bad, + * restore it from the good copy. + * + * Return: 0 if OK, -ve on error +*/ +int fwu_get_verified_mdata(struct fwu_mdata *mdata); + /** * fwu_check_mdata_validity() - Check for validity of the FWU metadata copies * diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index 5313d07302..4554654727 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -15,13 +15,13 @@ #include #include +#include + +static struct fwu_mdata g_mdata; /* = {0} makes uninit crc32 always invalid */ +static struct udevice *g_dev; static u8 in_trial; static u8 boottime_check; -#include -#include -#include - enum { IMAGE_ACCEPT_SET = 1, IMAGE_ACCEPT_CLEAR, @@ -161,6 +161,140 @@ static int fwu_get_image_type_id(u8 *image_index, efi_guid_t *image_type_id) return -ENOENT; } +/** + * fwu_sync_mdata() - Update given meta-data partition(s) with the copy provided + * @mdata: FWU metadata structure + * @part: Bitmask of FWU metadata partitions to be written to + * + * Return: 0 if OK, -ve on error + */ +static int fwu_sync_mdata(struct fwu_mdata *mdata, int part) +{ + void *buf = &mdata->version; + int err = 0; + + /* + * Calculate the crc32 for the updated FWU metadata + * and put the updated value in the FWU metadata crc32 + * field + */ + mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32)); + + if (part & PRIMARY_PART) + err = fwu_write_mdata(g_dev, mdata, true); + + if (err) { + log_err("Unable to write primary mdata\n"); + return err; + } + + if (part & SECONDARY_PART) + err = fwu_write_mdata(g_dev, mdata, false); + + if (err) { + log_err("Unable to write secondary mdata\n"); + return err; + } + + /* update the cached copy of meta-data */ + memcpy(&g_mdata, mdata, sizeof(struct fwu_mdata)); + + return 0; +} + +static inline int mdata_crc_check(struct fwu_mdata *mdata) +{ + void *buf = &mdata->version; + u32 calc_crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32)); + + return calc_crc32 == mdata->crc32 ? 0 : -EINVAL; +} + +/** + * fwu_get_verified_mdata() - Read, verify and return the FWU metadata + * + * Read both the metadata copies from the storage media, verify their checksum, + * and ascertain that both copies match. If one of the copies has gone bad, + * restore it from the good copy. + * + * Return: 0 if OK, -ve on error + */ +int fwu_get_verified_mdata(struct fwu_mdata *mdata) +{ + int err; + bool pri_ok, sec_ok; + struct fwu_mdata s, *p_mdata, *s_mdata; + + p_mdata = &g_mdata; + s_mdata = &s; + + /* if mdata already read and ready */ + err = mdata_crc_check(p_mdata); + if (!err) + goto ret_mdata; + /* else read, verify and, if needed, fix mdata */ + + pri_ok = false; + err = fwu_read_mdata(g_dev, p_mdata, true); + if (!err) { + err = mdata_crc_check(p_mdata); + if (!err) + pri_ok = true; + else + log_debug("primary mdata: crc32 failed\n"); + } + + sec_ok = false; + err = fwu_read_mdata(g_dev, s_mdata, false); + if (!err) { + err = mdata_crc_check(s_mdata); + if (!err) + sec_ok = true; + else + log_debug("secondary mdata: crc32 failed\n"); + } + + if (pri_ok && sec_ok) { + /* + * Before returning, check that both the + * FWU metadata copies are the same. + */ + err = memcmp(p_mdata, s_mdata, sizeof(struct fwu_mdata)); + if (!err) + goto ret_mdata; + + /* + * If not, populate the secondary partition from the + * primary partition copy. + */ + log_info("Both FWU metadata copies are valid but do not match."); + log_info(" Restoring the secondary partition from the primary\n"); + sec_ok = false; + } + + if (!pri_ok) { + memcpy(p_mdata, s_mdata, sizeof(struct fwu_mdata)); + err = fwu_sync_mdata(p_mdata, PRIMARY_PART); + if (err) + goto ret_mdata; + } + + if (!sec_ok) { + memcpy(s_mdata, p_mdata, sizeof(struct fwu_mdata)); + err = fwu_sync_mdata(s_mdata, SECONDARY_PART); + if (err) + goto ret_mdata; + } + +ret_mdata: + if (err) + log_debug("mdata : crc32 failed\n"); + else if (mdata) + memcpy(mdata, p_mdata, sizeof(struct fwu_mdata)); + + return err; +} + /** * fwu_verify_mdata() - Verify the FWU metadata * @mdata: FWU metadata structure From patchwork Mon Jan 2 18:26:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 638432 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp942648pvb; Mon, 2 Jan 2023 10:27:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXsQup8maQ0er1KAoH7HmYLOIAPfnoIc66xJXqT/W7oujU+aI/45cLhZ8Yurzs0CLPFiPKm6 X-Received: by 2002:a9d:7649:0:b0:670:73eb:5088 with SMTP id o9-20020a9d7649000000b0067073eb5088mr24207374otl.37.1672684022436; Mon, 02 Jan 2023 10:27:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672684022; cv=none; d=google.com; s=arc-20160816; b=OKAsCoLAPMKsuUKZ3Q6FHysTnwmSg697woc76J6p64xEQ28Oxp4JWzTCPYJ5hkW4th qmy5fMnytk6BxtObKPPz0p45333u/zuhhJz8K7M8SBixIgXtxwvGCxZvmZBSTke1RfEt fymSBCDozzJGsH7KJMscuR3jk313tq8OPsnKk8kpRwghwoB39BP7pds0O0VnsDOUB8+s qxtJStrXyYlp39uS6c1KaFvPLOBFB6PEQOrT4ggTfnKVTK4WOu+JOFFWMKQQgEIPwE/j sr2dXs0WoUbepJTN4u2aMKgkR9bqWwAVfYEo35di0g5BHUjPUsMIxhH8VGd/EnFeotoP TPgg== 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=IgnhbFDR1O4EahyVuA56qeTT9xedD31RLmbrq3fcc/c=; b=troiHV2+qWoCw7cCU4Lz5BhTl1RXHFur1sGLgeb8eJRINjUIeVyE5lcPNd4VsjWIGO ozZ2VTD9hp878cuLcT5RjiLCBMYLMEDh7P2ehPII59qdLKa5BMnb71r0uJ3iJubMqsfk xzUhpCeALH3KKitzprvQ+SH5LhofqWhRt4kzf32ipYh+4XohYJ/taZRWWYxWjPbRQfQF SZfFGq1+u5B61FZCNwf0W+0mtzAdUxxjm7FW5KfAxrhOGrnr/GBC6BT+ROw4XEQU00+L kBNXEQaPsC4+hPVaQ9ZT49+6pmsDS1Z6GlkxRQgNgW/CW3MrOAUkQI1N+TZRBj3xlEwE Xl2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=F+fkQ0GO; 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 r16-20020a05683001d000b0067079c41045si20202377ota.326.2023.01.02.10.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:27:02 -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=F+fkQ0GO; 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 73F2C85547; Mon, 2 Jan 2023 19:26:59 +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="F+fkQ0GO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6FD508553E; Mon, 2 Jan 2023 19:26:57 +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-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) (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 B49A08533F for ; Mon, 2 Jan 2023 19:26:54 +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-x135.google.com with SMTP id o13so16888419ilc.7 for ; Mon, 02 Jan 2023 10:26:54 -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=IgnhbFDR1O4EahyVuA56qeTT9xedD31RLmbrq3fcc/c=; b=F+fkQ0GOE/BstwULCGN8NzVAGaU34uqmMhTz/fSsKCApvA5i4risXZK8GzxhHz8sjR bMPRj9TtScyhoPYojiT5Y4Y+p0ivh+Ile0sY0PW8Es7nLkr1R27Cmxxf3lVliiU0KN0W 6yQdcFWPqeV/nG8chPpVykahtrq6kTGJ7dlDrZjjTa93WYUWbG9x8epjJcrzc8YJZneM ha2tN9WKo7Ju627QNd/XgX5kGzhRIsHzNEBTe99WcgYeA504f5Qpvfxop3JpYb2LSmEB hKSNX6H5XOOBwm5JgN/A6T/iKgK9M3t9HtcR8Lui+Z1Kvpxz4Yl5gq+Ak0Bt2UHWlAaM l91w== 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=IgnhbFDR1O4EahyVuA56qeTT9xedD31RLmbrq3fcc/c=; b=GYb/RRh8AFvKGUzm/5hNXg+16fmhckWOs3OrcWYNIMhiSYrTlk77xMebPHVZ5soVVF DpexaDwHS3+b0L4GWugbuPsR8feMG8GIOwwFJL3GRq+eS0Y7VUvA6EOsYrsmXdv6BKCO Q51wwF+V6OMlB9mkKYmhjDCJ6eHWcr+SIH2XXpdwNZqGQcJHOj1ud0PBXSmkoLS8oNet Z+F6TYKhs5fkl+uYFcuc+I07gClruvSLtvnJ9k3Y/Linf7dKtgFqX1kJqrdCaOCg9m7d Rdh+YkKsZ++BNtNLHe47SA4JZkUAB0qNZ02kMZAIbAMnlFTR4QoUd67cje2EfzQ+yUmZ O7dw== X-Gm-Message-State: AFqh2kqS9RoI80oraH2kdaUp+PN8EM9W6WK8v7/kUyZE/AwtuhqBK/LA dwsp+7T9NIlye3wx/FQdy/gqW//eDGA= X-Received: by 2002:a05:6e02:2169:b0:303:6d1e:e5d1 with SMTP id s9-20020a056e02216900b003036d1ee5d1mr43890169ilv.6.1672684013044; Mon, 02 Jan 2023 10:26:53 -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 w9-20020a05663800c900b0036cc14af7adsm9642424jao.149.2023.01.02.10.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:26:52 -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 3/5] fwu: gpt: implement read_mdata and write_mdata callbacks Date: Mon, 2 Jan 2023 12:26:49 -0600 Message-Id: <20230102182649.2411239-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 Moving towards using common code for meta-data management, implement the read/write mdata hooks. Signed-off-by: Jassi Brar Reviewed-by: Etienne Carriere Reviewed-by: Ilias Apalodimas --- drivers/fwu-mdata/gpt_blk.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/fwu-mdata/gpt_blk.c b/drivers/fwu-mdata/gpt_blk.c index 28f5d23e1e..bdaa10cd1d 100644 --- a/drivers/fwu-mdata/gpt_blk.c +++ b/drivers/fwu-mdata/gpt_blk.c @@ -272,7 +272,43 @@ static int fwu_mdata_gpt_blk_probe(struct udevice *dev) return 0; } +static int fwu_gpt_read_mdata(struct udevice *dev, struct fwu_mdata *mdata, + bool primary) +{ + struct fwu_mdata_gpt_blk_priv *priv = dev_get_priv(dev); + struct blk_desc *desc = dev_get_uclass_plat(priv->blk_dev); + int ret; + + ret = gpt_get_mdata_partitions(desc); + if (ret < 0) { + log_debug("Error getting the FWU metadata partitions\n"); + return -ENOENT; + } + + return gpt_read_write_mdata(desc, mdata, MDATA_READ, + primary ? g_mdata_part[0] : g_mdata_part[1]); +} + +static int fwu_gpt_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, + bool primary) +{ + struct fwu_mdata_gpt_blk_priv *priv = dev_get_priv(dev); + struct blk_desc *desc = dev_get_uclass_plat(priv->blk_dev); + int ret; + + ret = gpt_get_mdata_partitions(desc); + if (ret < 0) { + log_debug("Error getting the FWU metadata partitions\n"); + return -ENOENT; + } + + return gpt_read_write_mdata(desc, mdata, MDATA_WRITE, + primary ? g_mdata_part[0] : g_mdata_part[1]); +} + static const struct fwu_mdata_ops fwu_gpt_blk_ops = { + .read_mdata = fwu_gpt_read_mdata, + .write_mdata = fwu_gpt_write_mdata, .get_mdata = fwu_gpt_get_mdata, .update_mdata = fwu_gpt_update_mdata, .get_mdata_part_num = fwu_gpt_get_mdata_partitions, From patchwork Mon Jan 2 18:26:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 638433 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp942696pvb; Mon, 2 Jan 2023 10:27:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXs9R26kRkqyzuMQ9lKj5idQISzdEpV6Xo4ih7p6oDW/SKS3g4Tdt0xGrBngrAxM1/9UhVbb X-Received: by 2002:a05:6808:298c:b0:361:1a1:316 with SMTP id ex12-20020a056808298c00b0036101a10316mr16952788oib.33.1672684033376; Mon, 02 Jan 2023 10:27:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672684033; cv=none; d=google.com; s=arc-20160816; b=SMx6JJaTAtNKFzzG8huHFm7eFvgmYZ0Rap9/M63W9CAOk5NRwkyvzDLB4b89rTxMN8 vahaZrceecxzKp1uJjhli0b5MsEkhLgHfYBUe5nG/iW+GGg3pQmm2uNDtKu8d2EY6WL7 SVBmxT7fENNoLbjlC5FpdCQtke7wvSpjXfejVaC4WDWAvOzO6Qy6tF4y7rZDmTjOpERJ MgGQsvvzur/DJx20BpHMyh2KsXcL5dvEYU4rlteS0K2SkIa+GAfX4f9HopC5yGn4mPTE 9Hh1P96gnlacp3/+9+qQleneD/7FuSLoFXndvpSf9Fq3pNXTrtxhTZXojYlBCHHFbCDE lydQ== 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=8G2/whuzJ9aicYJKHb+cvsAKoQrXps/hcjWTfnJHnQ0=; b=eJhYdZiTVt4eKQJmxvs7+XzBnJTSSithCrTdvbUL7PSmKH00tt7E1wW6NY7Ykh4nJe 5QjgdK+FhzN/FEDQc/Kp3l32foWBIQH5TCbUDkDPL45BpryhXrAB5wxgvWBCkwig+Yie 0bB2hAEjeZKtYF0AIoi9MWdUtKz6d4CatJ2W2048ewrC0a1pwSw92HZbSmwnTWPzv2Kx fSEhkK0ko9SGSE+Ebkos9J5ZxEwvBe8ZRSa0auMRU8FzCHicl/iuBPw2dVy4TSut+j2z MC3o2MWeKVFv0Hp1cX8Yz6Ji7NFhVf1zSLxOhow4WVtcV5ufWl2o9QVgu77gRd2HY+Rf VJbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=e+DC1Iee; 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 u12-20020a056808114c00b0035e7e09ab25si27945682oiu.36.2023.01.02.10.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:27:13 -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=e+DC1Iee; 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 C3F5885551; Mon, 2 Jan 2023 19:27:09 +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="e+DC1Iee"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 96EE98554C; Mon, 2 Jan 2023 19:27:08 +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-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) (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 A5CF48553A for ; Mon, 2 Jan 2023 19:27: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=jassisinghbrar@gmail.com Received: by mail-il1-x12f.google.com with SMTP id a9so4558817ilk.6 for ; Mon, 02 Jan 2023 10:27:02 -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=8G2/whuzJ9aicYJKHb+cvsAKoQrXps/hcjWTfnJHnQ0=; b=e+DC1IeeIzmwOFshtVsc5L9mjnWy2Yq/L0+9mysdHzopAFDfGWFy5GgdtdPccpQu6O xLrrvK+YfCKk7FXbdjMtycsuu6618LWr/mnHllfEJIe+oD0qoyEbYtJGyG87lyMDsS5S CYCD5QCDt5WVpd4+HHAycHHCJMm0Tka2I65SlmhyNAxMEBpr5YOeScSFp6NaaJ784UOo K3MO2gVXSRrrztV0GsQZm4wb3uqX6FrZiT8nNA2u1Sbw/UPA0lkyp7FLt06CSi+k6zTY 543Yv5BVibhcBNHKxkMSqj5nRdzSb6pZb/+kdu3zOmJPtV71ImhdISXbCqPlCtUCah6/ C0bw== 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=8G2/whuzJ9aicYJKHb+cvsAKoQrXps/hcjWTfnJHnQ0=; b=QUV7Eo4I7Wohc6G+eG/xmKL0amqNUEfhHsc14N3p/f8bTD7YOWwTgaR8nXBTr9cFgq 3M/GleRZdZqtu0IychpcEI5eq7M6Jqox6HQIdArmDKHHC4NviXOs7RouptPh2nK+Dspp 5pskdjtgn+laXPAMMi7/W/XgJmoyvubKLF/e6QEoV95oD/Kzf5z42ZVX1BsLa4y+fZvp hzm2tIdUFswtxxMIjW8wOOpcQkwzyIQaHVKtyoQ9Q6zCurF+ED/qeKtpkoTMJDIEGuv9 WWla+vNbvdhVnnqFXww8L83u/3+Ny50scZJr/AbCc0fqApQTvuqAd28Hgk7lN6IYABRw 0dnA== X-Gm-Message-State: AFqh2kqDP4ttT2VgLy4Dwx0/I2ccy4HDg9VJG2sfTOzIh6KNdCv1oklb s/5nyI47xKGFhv6kZX4tfyPOqKFxGKE= X-Received: by 2002:a05:6e02:50b:b0:30c:87a:2804 with SMTP id d11-20020a056e02050b00b0030c087a2804mr17505291ils.29.1672684020296; Mon, 02 Jan 2023 10:27:00 -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 o4-20020a02b804000000b0038aaccd3bf3sm9124050jam.39.2023.01.02.10.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:26:59 -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 4/5] fwu: meta-data: switch to management by common code Date: Mon, 2 Jan 2023 12:26:56 -0600 Message-Id: <20230102182656.2411258-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 The common code can now read, verify and fix meta-data copies while exposing one consistent structure to users. Only the .read_mdata() and .write_mdata() callbacks of fwu_mdata_ops are needed. Get rid of .get_mdata() .update_mdata() .get_mdata_part_num() .read_mdata_partition() and .write_mdata_partition() and also the corresponding wrapper functions. Signed-off-by: Jassi Brar --- cmd/fwu_mdata.c | 17 +- drivers/fwu-mdata/fwu-mdata-uclass.c | 165 ------------------- drivers/fwu-mdata/gpt_blk.c | 124 +------------- include/fwu.h | 199 ----------------------- lib/fwu_updates/fwu.c | 235 ++++----------------------- 5 files changed, 38 insertions(+), 702 deletions(-) diff --git a/cmd/fwu_mdata.c b/cmd/fwu_mdata.c index f04af27de6..9b70340368 100644 --- a/cmd/fwu_mdata.c +++ b/cmd/fwu_mdata.c @@ -43,23 +43,10 @@ static void print_mdata(struct fwu_mdata *mdata) int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) { - struct udevice *dev; int ret = CMD_RET_SUCCESS, res; - struct fwu_mdata mdata = { 0 }; + struct fwu_mdata mdata; - if (uclass_get_device(UCLASS_FWU_MDATA, 0, &dev) || !dev) { - log_err("Unable to get FWU metadata device\n"); - return CMD_RET_FAILURE; - } - - res = fwu_check_mdata_validity(); - if (res < 0) { - log_err("FWU Metadata check failed\n"); - ret = CMD_RET_FAILURE; - goto out; - } - - res = fwu_get_mdata(dev, &mdata); + res = fwu_get_verified_mdata(&mdata); if (res < 0) { log_err("Unable to get valid FWU metadata\n"); ret = CMD_RET_FAILURE; diff --git a/drivers/fwu-mdata/fwu-mdata-uclass.c b/drivers/fwu-mdata/fwu-mdata-uclass.c index e03773c584..0a8edaaa41 100644 --- a/drivers/fwu-mdata/fwu-mdata-uclass.c +++ b/drivers/fwu-mdata/fwu-mdata-uclass.c @@ -14,7 +14,6 @@ #include #include -#include /** * fwu_read_mdata() - Wrapper around fwu_mdata_ops.read_mdata() @@ -50,170 +49,6 @@ int fwu_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary) return ops->write_mdata(dev, mdata, primary); } -/** - * fwu_get_mdata_part_num() - Get the FWU metadata partition numbers - * @dev: FWU metadata device - * @mdata_parts: array for storing the metadata partition numbers - * - * Get the partition numbers on the storage device on which the - * FWU metadata is stored. Two partition numbers will be returned. - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_get_mdata_part_num(struct udevice *dev, uint *mdata_parts) -{ - const struct fwu_mdata_ops *ops = device_get_ops(dev); - - if (!ops->get_mdata_part_num) { - log_debug("get_mdata_part_num() method not defined\n"); - return -ENOSYS; - } - - return ops->get_mdata_part_num(dev, mdata_parts); -} - -/** - * fwu_read_mdata_partition() - Read the FWU metadata from a partition - * @dev: FWU metadata device - * @mdata: Copy of the FWU metadata - * @part_num: Partition number from which FWU metadata is to be read - * - * Read the FWU metadata from the specified partition number - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_read_mdata_partition(struct udevice *dev, struct fwu_mdata *mdata, - uint part_num) -{ - const struct fwu_mdata_ops *ops = device_get_ops(dev); - - if (!ops->read_mdata_partition) { - log_debug("read_mdata_partition() method not defined\n"); - return -ENOSYS; - } - - return ops->read_mdata_partition(dev, mdata, part_num); -} - -/** - * fwu_write_mdata_partition() - Write the FWU metadata to a partition - * @dev: FWU metadata device - * @mdata: Copy of the FWU metadata - * @part_num: Partition number to which FWU metadata is to be written - * - * Write the FWU metadata to the specified partition number - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_write_mdata_partition(struct udevice *dev, struct fwu_mdata *mdata, - uint part_num) -{ - const struct fwu_mdata_ops *ops = device_get_ops(dev); - - if (!ops->write_mdata_partition) { - log_debug("write_mdata_partition() method not defined\n"); - return -ENOSYS; - } - - return ops->write_mdata_partition(dev, mdata, part_num); -} - -/** - * fwu_mdata_check() - Check if the FWU metadata is valid - * @dev: FWU metadata device - * - * Validate both copies of the FWU metadata. If one of the copies - * has gone bad, restore it from the other copy. - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_mdata_check(struct udevice *dev) -{ - const struct fwu_mdata_ops *ops = device_get_ops(dev); - - if (!ops->check_mdata) { - log_debug("check_mdata() method not defined\n"); - return -ENOSYS; - } - - return ops->check_mdata(dev); -} - -/** - * fwu_get_mdata() - Get a FWU metadata copy - * @dev: FWU metadata device - * @mdata: Copy of the FWU metadata - * - * Get a valid copy of the FWU metadata. - * - * Note: This function is to be called first when modifying any fields - * in the metadata. The sequence of calls to modify any field in the - * metadata would be 1) fwu_get_mdata 2) Modify metadata, followed by - * 3) fwu_update_mdata - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_get_mdata(struct udevice *dev, struct fwu_mdata *mdata) -{ - const struct fwu_mdata_ops *ops = device_get_ops(dev); - - if (!ops->get_mdata) { - log_debug("get_mdata() method not defined\n"); - return -ENOSYS; - } - - return ops->get_mdata(dev, mdata); -} - -/** - * fwu_update_mdata() - Update the FWU metadata - * @dev: FWU metadata device - * @mdata: Copy of the FWU metadata - * - * Update the FWU metadata structure by writing to the - * FWU metadata partitions. - * - * Note: This function is not to be called directly to update the - * metadata fields. The sequence of function calls should be - * 1) fwu_get_mdata() 2) Modify the medata fields 3) fwu_update_mdata() - * - * The sequence of updating the partitions should be, update the - * primary metadata partition (first partition encountered), followed - * by updating the secondary partition. With this update sequence, in - * the rare scenario that the two metadata partitions are valid but do - * not match, maybe due to power outage at the time of updating the - * metadata copies, the secondary partition can be updated from the - * primary. - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_update_mdata(struct udevice *dev, struct fwu_mdata *mdata) -{ - void *buf; - const struct fwu_mdata_ops *ops = device_get_ops(dev); - - if (!ops->update_mdata) { - log_debug("get_mdata() method not defined\n"); - return -ENOSYS; - } - - /* - * Calculate the crc32 for the updated FWU metadata - * and put the updated value in the FWU metadata crc32 - * field - */ - buf = &mdata->version; - mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32)); - - return ops->update_mdata(dev, mdata); -} - UCLASS_DRIVER(fwu_mdata) = { .id = UCLASS_FWU_MDATA, .name = "fwu-mdata", diff --git a/drivers/fwu-mdata/gpt_blk.c b/drivers/fwu-mdata/gpt_blk.c index bdaa10cd1d..b3c6953a6e 100644 --- a/drivers/fwu-mdata/gpt_blk.c +++ b/drivers/fwu-mdata/gpt_blk.c @@ -28,7 +28,7 @@ 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; + int i; u32 nparts; efi_guid_t part_type_guid; struct disk_partition info; @@ -52,12 +52,12 @@ static int gpt_get_mdata_partitions(struct blk_desc *desc) if (nparts != 2) { log_debug("Expect two copies of the FWU metadata instead of %d\n", nparts); - ret = -EINVAL; - } else { - ret = 0; + g_mdata_part[0] = 0; + g_mdata_part[1] = 0; + return -EINVAL; } - return ret; + return 0; } static int gpt_get_mdata_disk_part(struct blk_desc *desc, @@ -125,115 +125,6 @@ static int gpt_read_write_mdata(struct blk_desc *desc, return 0; } -static int fwu_gpt_update_mdata(struct udevice *dev, struct fwu_mdata *mdata) -{ - int ret; - struct blk_desc *desc; - 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); - 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, 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, g_mdata_part[1]); - if (ret < 0) { - log_debug("Updating secondary FWU metadata partition failed\n"); - return ret; - } - - return 0; -} - -static int gpt_get_mdata(struct blk_desc *desc, struct fwu_mdata *mdata) -{ - int ret; - - 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, g_mdata_part[0]); - if (ret < 0) { - log_debug("Failed to read the FWU metadata from the device\n"); - return -EIO; - } - - ret = fwu_verify_mdata(mdata, 1); - if (!ret) - return 0; - - /* - * Verification of the primary FWU metadata copy failed. - * Try to read the replica. - */ - memset(mdata, '\0', sizeof(struct fwu_mdata)); - 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; - } - - ret = fwu_verify_mdata(mdata, 0); - if (!ret) - return 0; - - /* Both the FWU metadata copies are corrupted. */ - return -EIO; -} - -static int fwu_gpt_get_mdata(struct udevice *dev, struct fwu_mdata *mdata) -{ - struct fwu_mdata_gpt_blk_priv *priv = dev_get_priv(dev); - - return gpt_get_mdata(dev_get_uclass_plat(priv->blk_dev), 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 err; -} - -static int fwu_gpt_read_mdata_partition(struct udevice *dev, - struct fwu_mdata *mdata, uint part_num) -{ - struct fwu_mdata_gpt_blk_priv *priv = dev_get_priv(dev); - - return gpt_read_write_mdata(dev_get_uclass_plat(priv->blk_dev), - mdata, MDATA_READ, part_num); -} - -static int fwu_gpt_write_mdata_partition(struct udevice *dev, - struct fwu_mdata *mdata, uint part_num) -{ - struct fwu_mdata_gpt_blk_priv *priv = dev_get_priv(dev); - - return gpt_read_write_mdata(dev_get_uclass_plat(priv->blk_dev), - mdata, MDATA_WRITE, part_num); -} - static int fwu_get_mdata_device(struct udevice *dev, struct udevice **mdata_dev) { u32 phandle; @@ -309,11 +200,6 @@ static int fwu_gpt_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, static const struct fwu_mdata_ops fwu_gpt_blk_ops = { .read_mdata = fwu_gpt_read_mdata, .write_mdata = fwu_gpt_write_mdata, - .get_mdata = fwu_gpt_get_mdata, - .update_mdata = fwu_gpt_update_mdata, - .get_mdata_part_num = fwu_gpt_get_mdata_partitions, - .read_mdata_partition = fwu_gpt_read_mdata_partition, - .write_mdata_partition = fwu_gpt_write_mdata_partition, }; static const struct udevice_id fwu_mdata_ids[] = { diff --git a/include/fwu.h b/include/fwu.h index 1a700c9e6a..23bd97fe86 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -18,11 +18,6 @@ struct fwu_mdata_gpt_blk_priv { struct udevice *blk_dev; }; -/** - * @mdata_check: check the validity of the FWU metadata partitions - * @get_mdata() - Get a FWU metadata copy - * @update_mdata() - Update the FWU metadata copy - */ struct fwu_mdata_ops { /** * read_mdata() - Populate the asked FWU metadata copy @@ -43,78 +38,6 @@ struct fwu_mdata_ops { * Return: 0 if OK, -ve on error */ int (*write_mdata)(struct udevice *dev, struct fwu_mdata *mdata, bool primary); - - /** - * check_mdata() - Check if the FWU metadata is valid - * @dev: FWU device - * - * Validate both copies of the FWU metadata. If one of the copies - * has gone bad, restore it from the other copy. - * - * Return: 0 if OK, -ve on error - */ - int (*check_mdata)(struct udevice *dev); - - /** - * get_mdata() - Get a FWU metadata copy - * @dev: FWU device - * @mdata: Pointer to FWU metadata - * - * Get a valid copy of the FWU metadata. - * - * Return: 0 if OK, -ve on error - */ - int (*get_mdata)(struct udevice *dev, struct fwu_mdata *mdata); - - /** - * update_mdata() - Update the FWU metadata - * @dev: FWU device - * @mdata: Copy of the FWU metadata - * - * Update the FWU metadata structure by writing to the - * FWU metadata partitions. - * - * Return: 0 if OK, -ve on error - */ - int (*update_mdata)(struct udevice *dev, struct fwu_mdata *mdata); - - /** - * get_mdata_part_num() - Get the FWU metadata partition numbers - * @dev: FWU metadata device - * @mdata_parts: array for storing the metadata partition numbers - * - * Get the partition numbers on the storage device on which the - * FWU metadata is stored. Two partition numbers will be returned. - * - * Return: 0 if OK, -ve on error - */ - int (*get_mdata_part_num)(struct udevice *dev, uint *mdata_parts); - - /** - * read_mdata_partition() - Read the FWU metadata from a partition - * @dev: FWU metadata device - * @mdata: Copy of the FWU metadata - * @part_num: Partition number from which FWU metadata is to be read - * - * Read the FWU metadata from the specified partition number - * - * Return: 0 if OK, -ve on error - */ - int (*read_mdata_partition)(struct udevice *dev, - struct fwu_mdata *mdata, uint part_num); - - /** - * write_mdata_partition() - Write the FWU metadata to a partition - * @dev: FWU metadata device - * @mdata: Copy of the FWU metadata - * @part_num: Partition number to which FWU metadata is to be written - * - * Write the FWU metadata to the specified partition number - * - * Return: 0 if OK, -ve on error - */ - int (*write_mdata_partition)(struct udevice *dev, - struct fwu_mdata *mdata, uint part_num); }; #define FWU_MDATA_VERSION 0x1 @@ -167,102 +90,6 @@ int fwu_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary); */ int fwu_get_verified_mdata(struct fwu_mdata *mdata); -/** - * fwu_check_mdata_validity() - Check for validity of the FWU metadata copies - * - * Read both the metadata copies from the storage media, verify their - * checksum, and ascertain that both copies match. If one of the copies - * has gone bad, restore it from the good copy. - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_check_mdata_validity(void); - -/** - * fwu_get_mdata_part_num() - Get the FWU metadata partition numbers - * @dev: FWU metadata device - * @mdata_parts: array for storing the metadata partition numbers - * - * Get the partition numbers on the storage device on which the - * FWU metadata is stored. Two partition numbers will be returned - * through the array. - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_get_mdata_part_num(struct udevice *dev, uint *mdata_parts); - -/** - * fwu_read_mdata_partition() - Read the FWU metadata from a partition - * @dev: FWU metadata device - * @mdata: Copy of the FWU metadata - * @part_num: Partition number from which FWU metadata is to be read - * - * Read the FWU metadata from the specified partition number - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_read_mdata_partition(struct udevice *dev, struct fwu_mdata *mdata, - uint part_num); - -/** - * fwu_write_mdata_partition() - Write the FWU metadata to a partition - * @dev: FWU metadata device - * @mdata: Copy of the FWU metadata - * @part_num: Partition number to which FWU metadata is to be written - * - * Write the FWU metadata to the specified partition number - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_write_mdata_partition(struct udevice *dev, struct fwu_mdata *mdata, - uint part_num); - -/** - * fwu_get_mdata() - Get a FWU metadata copy - * @dev: FWU metadata device - * @mdata: Copy of the FWU metadata - * - * Get a valid copy of the FWU metadata. - * - * Note: This function is to be called first when modifying any fields - * in the metadata. The sequence of calls to modify any field in the - * metadata would be 1) fwu_get_mdata 2) Modify metadata, followed by - * 3) fwu_update_mdata - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_get_mdata(struct udevice *dev, struct fwu_mdata *mdata); - -/** - * fwu_update_mdata() - Update the FWU metadata - * @dev: FWU metadata device - * @mdata: Copy of the FWU metadata - * - * Update the FWU metadata structure by writing to the - * FWU metadata partitions. - * - * Note: This function is not to be called directly to update the - * metadata fields. The sequence of function calls should be - * 1) fwu_get_mdata() 2) Modify the medata fields 3) fwu_update_mdata() - * - * The sequence of updating the partitions should be, update the - * primary metadata partition (first partition encountered), followed - * by updating the secondary partition. With this update sequence, in - * the rare scenario that the two metadata partitions are valid but do - * not match, maybe due to power outage at the time of updating the - * metadata copies, the secondary partition can be updated from the - * primary. - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_update_mdata(struct udevice *dev, struct fwu_mdata *mdata); - /** * fwu_get_active_index() - Get active_index from the FWU metadata * @active_idxp: active_index value to be read @@ -303,18 +130,6 @@ int fwu_set_active_index(uint active_idx); */ int fwu_get_image_index(u8 *image_index); -/** - * fwu_mdata_check() - Check if the FWU metadata is valid - * @dev: FWU metadata device - * - * Validate both copies of the FWU metadata. If one of the copies - * has gone bad, restore it from the other copy. - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_mdata_check(struct udevice *dev); - /** * fwu_revert_boot_index() - Revert the active index in the FWU metadata * @@ -327,20 +142,6 @@ int fwu_mdata_check(struct udevice *dev); */ int fwu_revert_boot_index(void); -/** - * fwu_verify_mdata() - Verify the FWU metadata - * @mdata: FWU metadata structure - * @pri_part: FWU metadata partition is primary or secondary - * - * Verify the FWU metadata by computing the CRC32 for the metadata - * structure and comparing it against the CRC32 value stored as part - * of the structure. - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_verify_mdata(struct fwu_mdata *mdata, bool pri_part); - /** * fwu_accept_image() - Set the Acceptance bit for the image * @img_type_id: GUID of the image type for which the accepted bit is to be diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index 4554654727..234882af9a 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -33,26 +33,6 @@ enum { BOTH_PARTS, }; -static int fwu_get_dev_mdata(struct udevice **dev, struct fwu_mdata *mdata) -{ - int ret; - - ret = uclass_first_device_err(UCLASS_FWU_MDATA, dev); - if (ret) { - log_debug("Cannot find fwu device\n"); - return ret; - } - - if (!mdata) - return 0; - - ret = fwu_get_mdata(*dev, mdata); - if (ret < 0) - log_debug("Unable to get valid FWU metadata\n"); - - return ret; -} - static int trial_counter_update(u16 *trial_state_ctr) { bool delete; @@ -295,136 +275,6 @@ ret_mdata: return err; } -/** - * fwu_verify_mdata() - Verify the FWU metadata - * @mdata: FWU metadata structure - * @pri_part: FWU metadata partition is primary or secondary - * - * Verify the FWU metadata by computing the CRC32 for the metadata - * structure and comparing it against the CRC32 value stored as part - * of the structure. - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_verify_mdata(struct fwu_mdata *mdata, bool pri_part) -{ - u32 calc_crc32; - void *buf; - - buf = &mdata->version; - calc_crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32)); - - if (calc_crc32 != mdata->crc32) { - log_debug("crc32 check failed for %s FWU metadata partition\n", - pri_part ? "primary" : "secondary"); - return -EINVAL; - } - - return 0; -} - -/** - * fwu_check_mdata_validity() - Check for validity of the FWU metadata copies - * - * Read both the metadata copies from the storage media, verify their checksum, - * and ascertain that both copies match. If one of the copies has gone bad, - * restore it from the good copy. - * - * Return: 0 if OK, -ve on error - * - */ -int fwu_check_mdata_validity(void) -{ - int ret; - struct udevice *dev; - struct fwu_mdata pri_mdata; - struct fwu_mdata secondary_mdata; - uint mdata_parts[2]; - uint valid_partitions, invalid_partitions; - - ret = fwu_get_dev_mdata(&dev, NULL); - if (ret) - return ret; - - /* - * Check if the platform has defined its own - * function to check the metadata partitions' - * validity. If so, that takes precedence. - */ - ret = fwu_mdata_check(dev); - if (!ret || ret != -ENOSYS) - return ret; - - /* - * Two FWU metadata partitions are expected. - * If we don't have two, user needs to create - * them first - */ - valid_partitions = 0; - ret = fwu_get_mdata_part_num(dev, mdata_parts); - if (ret < 0) { - log_debug("Error getting the FWU metadata partitions\n"); - return -ENOENT; - } - - ret = fwu_read_mdata_partition(dev, &pri_mdata, mdata_parts[0]); - if (!ret) { - ret = fwu_verify_mdata(&pri_mdata, 1); - if (!ret) - valid_partitions |= PRIMARY_PART; - } - - ret = fwu_read_mdata_partition(dev, &secondary_mdata, mdata_parts[1]); - if (!ret) { - ret = fwu_verify_mdata(&secondary_mdata, 0); - if (!ret) - valid_partitions |= SECONDARY_PART; - } - - if (valid_partitions == (PRIMARY_PART | SECONDARY_PART)) { - /* - * Before returning, check that both the - * FWU metadata copies are the same. If not, - * populate the secondary partition from the - * primary partition copy. - */ - if (!memcmp(&pri_mdata, &secondary_mdata, - sizeof(struct fwu_mdata))) { - ret = 0; - } else { - log_info("Both FWU metadata copies are valid but do not match."); - log_info(" Restoring the secondary partition from the primary\n"); - ret = fwu_write_mdata_partition(dev, &pri_mdata, - mdata_parts[1]); - if (ret) - log_debug("Restoring secondary FWU metadata partition failed\n"); - } - goto out; - } - - if (!(valid_partitions & BOTH_PARTS)) { - log_info("Both FWU metadata partitions invalid\n"); - ret = -EBADMSG; - goto out; - } - - invalid_partitions = valid_partitions ^ BOTH_PARTS; - ret = fwu_write_mdata_partition(dev, - (invalid_partitions == PRIMARY_PART) ? - &secondary_mdata : &pri_mdata, - (invalid_partitions == PRIMARY_PART) ? - mdata_parts[0] : mdata_parts[1]); - - if (ret) - log_debug("Restoring %s FWU metadata partition failed\n", - (invalid_partitions == PRIMARY_PART) ? - "primary" : "secondary"); - -out: - return ret; -} - /** * fwu_get_active_index() - Get active_index from the FWU metadata * @active_idx: active_index value to be read @@ -437,19 +287,14 @@ out: */ int fwu_get_active_index(uint *active_idx) { - int ret; - struct udevice *dev; - struct fwu_mdata mdata = { 0 }; - - ret = fwu_get_dev_mdata(&dev, &mdata); - if (ret) - return ret; + int ret = 0; + struct fwu_mdata *mdata = &g_mdata; /* * Found the FWU metadata partition, now read the active_index * value */ - *active_idx = mdata.active_index; + *active_idx = mdata->active_index; if (*active_idx >= CONFIG_FWU_NUM_BANKS) { log_debug("Active index value read is incorrect\n"); ret = -EINVAL; @@ -470,30 +315,25 @@ int fwu_get_active_index(uint *active_idx) int fwu_set_active_index(uint active_idx) { int ret; - struct udevice *dev; - struct fwu_mdata mdata = { 0 }; + struct fwu_mdata *mdata = &g_mdata; if (active_idx >= CONFIG_FWU_NUM_BANKS) { log_debug("Invalid active index value\n"); return -EINVAL; } - ret = fwu_get_dev_mdata(&dev, &mdata); - if (ret) - return ret; - /* * Update the active index and previous_active_index fields * in the FWU metadata */ - mdata.previous_active_index = mdata.active_index; - mdata.active_index = active_idx; + mdata->previous_active_index = mdata->active_index; + mdata->active_index = active_idx; /* * Now write this updated FWU metadata to both the * FWU metadata partitions */ - ret = fwu_update_mdata(dev, &mdata); + ret = fwu_sync_mdata(mdata, BOTH_PARTS); if (ret) { log_debug("Failed to update FWU metadata partitions\n"); ret = -EIO; @@ -523,15 +363,10 @@ int fwu_get_image_index(u8 *image_index) u8 alt_num; uint update_bank; efi_guid_t *image_guid, image_type_id; - struct udevice *dev; - struct fwu_mdata mdata = { 0 }; + struct fwu_mdata *mdata = &g_mdata; struct fwu_image_entry *img_entry; struct fwu_image_bank_info *img_bank_info; - ret = fwu_get_dev_mdata(&dev, &mdata); - if (ret) - return ret; - ret = fwu_plat_get_update_index(&update_bank); if (ret) { log_debug("Failed to get the FWU update bank\n"); @@ -552,11 +387,11 @@ int fwu_get_image_index(u8 *image_index) */ for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) { if (!guidcmp(&image_type_id, - &mdata.img_entry[i].image_type_uuid)) { - img_entry = &mdata.img_entry[i]; + &mdata->img_entry[i].image_type_uuid)) { + img_entry = &mdata->img_entry[i]; img_bank_info = &img_entry->img_bank_info[update_bank]; image_guid = &img_bank_info->image_uuid; - ret = fwu_plat_get_alt_num(dev, image_guid, &alt_num); + ret = fwu_plat_get_alt_num(g_dev, image_guid, &alt_num); if (ret) { log_debug("alt_num not found for partition with GUID %pUs\n", image_guid); @@ -591,26 +426,21 @@ int fwu_revert_boot_index(void) { int ret; u32 cur_active_index; - struct udevice *dev; - struct fwu_mdata mdata = { 0 }; - - ret = fwu_get_dev_mdata(&dev, &mdata); - if (ret) - return ret; + struct fwu_mdata *mdata = &g_mdata; /* * Swap the active index and previous_active_index fields * in the FWU metadata */ - cur_active_index = mdata.active_index; - mdata.active_index = mdata.previous_active_index; - mdata.previous_active_index = cur_active_index; + cur_active_index = mdata->active_index; + mdata->active_index = mdata->previous_active_index; + mdata->previous_active_index = cur_active_index; /* * Now write this updated FWU metadata to both the * FWU metadata partitions */ - ret = fwu_update_mdata(dev, &mdata); + ret = fwu_sync_mdata(mdata, BOTH_PARTS); if (ret) { log_debug("Failed to update FWU metadata partitions\n"); ret = -EIO; @@ -637,16 +467,11 @@ int fwu_revert_boot_index(void) static int fwu_clrset_image_accept(efi_guid_t *img_type_id, u32 bank, u8 action) { int ret, i; - struct udevice *dev; - struct fwu_mdata mdata = { 0 }; + struct fwu_mdata *mdata = &g_mdata; struct fwu_image_entry *img_entry; struct fwu_image_bank_info *img_bank_info; - ret = fwu_get_dev_mdata(&dev, &mdata); - if (ret) - return ret; - - img_entry = &mdata.img_entry[0]; + img_entry = &mdata->img_entry[0]; for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) { if (!guidcmp(&img_entry[i].image_type_uuid, img_type_id)) { img_bank_info = &img_entry[i].img_bank_info[bank]; @@ -655,7 +480,7 @@ static int fwu_clrset_image_accept(efi_guid_t *img_type_id, u32 bank, u8 action) else img_bank_info->accepted = 0; - ret = fwu_update_mdata(dev, &mdata); + ret = fwu_sync_mdata(mdata, BOTH_PARTS); goto out; } } @@ -790,8 +615,6 @@ static int fwu_boottime_checks(void *ctx, struct event *event) { int ret; u32 boot_idx, active_idx; - struct udevice *dev; - struct fwu_mdata mdata = { 0 }; /* Don't have boot time checks on sandbox */ if (IS_ENABLED(CONFIG_SANDBOX)) { @@ -799,9 +622,17 @@ static int fwu_boottime_checks(void *ctx, struct event *event) return 0; } - ret = fwu_check_mdata_validity(); - if (ret) - return 0; + ret = uclass_first_device_err(UCLASS_FWU_MDATA, &g_dev); + if (ret) { + log_debug("Cannot find fwu device\n"); + return ret; + } + + ret = fwu_get_verified_mdata(NULL); + if (ret) { + log_debug("Unable to read meta-data\n"); + return ret; + } /* * Get the Boot Index, i.e. the bank from @@ -837,11 +668,7 @@ static int fwu_boottime_checks(void *ctx, struct event *event) if (efi_init_obj_list() != EFI_SUCCESS) return 0; - ret = fwu_get_dev_mdata(&dev, &mdata); - if (ret) - return ret; - - in_trial = in_trial_state(&mdata); + in_trial = in_trial_state(&g_mdata); if (!in_trial || (ret = fwu_trial_count_update()) > 0) ret = trial_counter_update(NULL); From patchwork Mon Jan 2 18:27:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 638434 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp942752pvb; Mon, 2 Jan 2023 10:27:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXuHPbB/lEtxHzuiSAX1ivFI1Ivh6Q0qGsVcdoepwqumrADvP6ADAAhQjxBg52mkcYWXaIMA X-Received: by 2002:a05:6808:148d:b0:363:b790:7a95 with SMTP id e13-20020a056808148d00b00363b7907a95mr3433184oiw.10.1672684044900; Mon, 02 Jan 2023 10:27:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672684044; cv=none; d=google.com; s=arc-20160816; b=LlC4HvwDtF3wPojkdV2Vh3DR0sMY/piil4vogvCYuHhgXP33r9t1CRhwXms63dS+PR 1Z2pBE5Sp3t4ZB8Z2+fZJ4x5t4JK4IJcrZ7hHMqDwqp2K5Tk71cAI0dWa9TW3GKJYn4X aJOF8lql5fzAvYKsUGqFlvu/wS+UaBOWR2lp+OL/cpzoMTG7Z+JdJR4wEfV+Dtf44/I+ 2lYTTjbHyRBWYjLP2l0w5vh/BPJR/onxuHfyh+0t8AlxYhVgSi1Aj7ezc7sMlGDjlLQP qIKx14qvP6WZcL5MZBW3GZc3SXb8OpiIt9s8exawO5GP5kTq3zERAceNyz/CZs32j0T3 mmsA== 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=3SotUbs6sgWZcoDoBG+WKDzmTB/KYc7pk+krHvDJd5s=; b=fSLIVZ+LKg8KB1QwYiJPwUcAifB0wsWTcZVZFDynJE5P6W5rNyaAiInGmiVjNysZOn EHa5jTgHm+aSjHn3xXana3qoHAuXQtf1AWZLwhNlMQjvNh6X0QJybeSvoxHXX06op4HD U0V7WUHUSjDEPYT/4gpquNe0RsRjWBL02VtlFhjEOikCG/b3BW1SxwQCRD430hk+q0PZ 6UmEvLzw9Q1xghSGrZrFKwfX7kER6uskKBz++G1FI63GjBhs3ivheOZKnNs5K+eBSJKX ecKWk7RvL1p4V9vWS2sLcx5YRu4caYUbGABlYQZQSLNEW44knotr2Bjy2QX2rfP+DVL2 uvmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=N4BHIy9B; 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 bb33-20020a05680816a100b00360d6749defsi25371460oib.251.2023.01.02.10.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:27:24 -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=N4BHIy9B; 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 7FB4985413; Mon, 2 Jan 2023 19:27:14 +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="N4BHIy9B"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 96BCC851E4; Mon, 2 Jan 2023 19:27:12 +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-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) (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 765578554C for ; Mon, 2 Jan 2023 19:27:09 +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-xd31.google.com with SMTP id z126so4570303iof.13 for ; Mon, 02 Jan 2023 10:27:09 -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=3SotUbs6sgWZcoDoBG+WKDzmTB/KYc7pk+krHvDJd5s=; b=N4BHIy9B5UKcH9Ov61GamwYXeoQ7AhZBxV8QWIzEfwjtRBTr+aDSZWaHmwHaIi2ytD GMoKwukmh0nTrBnpsGNwTERZOP0Cz7lIEH+I8VaV1VO903ZEefnRryiPKxqj90YNxjd4 DAPHpxQCFRjb4VAc9ucmyTEufxYmfG0NdwO+u2h4w1MLzn8JP4CsOAqLJkl6OCeKaZlt Q1rtSEkyHr4JKUCq1zyXa61IQz8xiRkwbc+1GMhl8OIxRSU12g++hLEojG0tBLEAwKw9 I8mumpiHQkXSq3zOiLnhCqkF97IfQZI+mAqWtIj3+MQbVINbsINizpLmle/f8ibg6N+y pjvQ== 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=3SotUbs6sgWZcoDoBG+WKDzmTB/KYc7pk+krHvDJd5s=; b=LCbyfOhCkGW/I7DTyT4S9LGfcjnRD1pUtZud+U+BhU4IWnyYt8hP0iY+Ovg7Eb2WiW 2Ai8+pU4jUVi7lLgZMBmAsJ73m18dIzZ9Lz/u+VF4Di3cSDhe+oYFttTi49uTsKb7NsB 8PjFkYroiC+yJKRvCx5+dFhg47ra+IWnS0nz+OwKNPk4+wC2F0fUWsoMYaC0l0tUlOs/ loa/g6QSHqTBUlM9sJ0kpyuj9oPd0hal2mmLNcOXHPObeiLgGcZJ9vXVdSdUCmxv1CMu L5BXLywhf8Zo8D/73VOpgfD6ftgyV0xzGirjwtAA10NHwRxGvIjiDrWSqvvhCMTk5ITw ZuLA== X-Gm-Message-State: AFqh2kqJI9z1JZJXiFKr7bduJIrqJyKYDuWKYqVRK4ywPZFs862MbmW/ URhUMFUojXek3s+nKtANDspr9CQrj9Y= X-Received: by 2002:a6b:b4d1:0:b0:6ed:308f:f807 with SMTP id d200-20020a6bb4d1000000b006ed308ff807mr30239149iof.21.1672684027788; Mon, 02 Jan 2023 10:27:07 -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 o4-20020a02b804000000b0038aaccd3bf3sm9124125jam.39.2023.01.02.10.27.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:27:07 -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 5/5] fwu: rename fwu_get_verified_mdata to fwu_get_mdata Date: Mon, 2 Jan 2023 12:27:04 -0600 Message-Id: <20230102182704.2411290-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 fwu_get_mdata() sounds more appropriate than fwu_get_verified_mdata() Signed-off-by: Jassi Brar Reviewed-by: Etienne Carriere Reviewed-by: Ilias Apalodimas --- cmd/fwu_mdata.c | 2 +- include/fwu.h | 4 ++-- lib/fwu_updates/fwu.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/fwu_mdata.c b/cmd/fwu_mdata.c index 9b70340368..5ecda455df 100644 --- a/cmd/fwu_mdata.c +++ b/cmd/fwu_mdata.c @@ -46,7 +46,7 @@ int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag, int ret = CMD_RET_SUCCESS, res; struct fwu_mdata mdata; - res = fwu_get_verified_mdata(&mdata); + res = fwu_get_mdata(&mdata); if (res < 0) { log_err("Unable to get valid FWU metadata\n"); ret = CMD_RET_FAILURE; diff --git a/include/fwu.h b/include/fwu.h index 23bd97fe86..ea25aca2cd 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -80,7 +80,7 @@ int fwu_read_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary); int fwu_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary); /** - * fwu_get_verified_mdata() - Read, verify and return the FWU metadata + * fwu_get_mdata() - Read, verify and return the FWU metadata * * Read both the metadata copies from the storage media, verify their checksum, * and ascertain that both copies match. If one of the copies has gone bad, @@ -88,7 +88,7 @@ int fwu_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary); * * Return: 0 if OK, -ve on error */ -int fwu_get_verified_mdata(struct fwu_mdata *mdata); +int fwu_get_mdata(struct fwu_mdata *mdata); /** * fwu_get_active_index() - Get active_index from the FWU metadata diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index 234882af9a..75bcc01c13 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -191,7 +191,7 @@ static inline int mdata_crc_check(struct fwu_mdata *mdata) } /** - * fwu_get_verified_mdata() - Read, verify and return the FWU metadata + * fwu_get_mdata() - Read, verify and return the FWU metadata * * Read both the metadata copies from the storage media, verify their checksum, * and ascertain that both copies match. If one of the copies has gone bad, @@ -199,7 +199,7 @@ static inline int mdata_crc_check(struct fwu_mdata *mdata) * * Return: 0 if OK, -ve on error */ -int fwu_get_verified_mdata(struct fwu_mdata *mdata) +int fwu_get_mdata(struct fwu_mdata *mdata) { int err; bool pri_ok, sec_ok; @@ -628,7 +628,7 @@ static int fwu_boottime_checks(void *ctx, struct event *event) return ret; } - ret = fwu_get_verified_mdata(NULL); + ret = fwu_get_mdata(NULL); if (ret) { log_debug("Unable to read meta-data\n"); return ret;