From patchwork Sun Feb 5 03:00: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: 650894 Delivered-To: patch@linaro.org Received: by 2002:a17:522:d8c:b0:4be:c3dc:14d8 with SMTP id d12csp1636866pva; Sat, 4 Feb 2023 19:01:17 -0800 (PST) X-Google-Smtp-Source: AK7set/4Cy2TqaWUJphha+1xwbPwM0hkEWSiG1p0r6V4FH6XmIkOrIxK38Z5u/iBawoi4YtOgQjm X-Received: by 2002:aca:3688:0:b0:37b:9e0:dcec with SMTP id d130-20020aca3688000000b0037b09e0dcecmr1121402oia.58.1675566076899; Sat, 04 Feb 2023 19:01:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675566076; cv=none; d=google.com; s=arc-20160816; b=rYIIT/hVaA0AlgMcdM2foRdWMa/8QC/s3nJGrB3ohe1bVlD0BkY2FwkaiCzTLL4omb deTiuW6VNrcfwP2I7xnLijX66r+37UOEqlptWO/yXTwMvuAMghcCANSQDYb+k1RAmsXi HGb4C1LQvy9VCyFP4/wbnU8VJGaWwHZqI/2VWaqElT/b1EGaxV+C8VajqjbHfBp6kavg vpTnwQOi3fMFwR6JhvFqefnNoaQgi6sixzNEM82pn+8RO8su0yzdF0/TVc+xeapMB58i Ffdf7GBx88YJSmWLoSV5XStNSoTaV+vOSpp/V93c2cAWF/XJDKqTZsDPz1/6caZgZNMc oBBw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=83cyYLXLCt69D00PHCY8u+JaTb2r4DGw8zNIJhejsI0=; b=MyYZvV9n1l9nhDPT1TdznKdVnkQaP4gP2nO49iUh+U6SSWZ12yRnUtdWn/mED2F/Zf yrgS+WxX1ER1kduTCR1tTQOMRhzBQYeega+FM8GeP3qOjiTSGSHqi3tZX+21ijBEHvCu SqpKAFviwwTiTu4aiKVq9H3XgrLd8/msXWAsBYYZApuUpiHpEL7NrUGNKXpbUZ+bKXol Xwz3Iv07iN0vPOsn4guT0IJbUtGt9vVe8S+k8N0MOvTDAYjdpTN4Fo5qd8sdfgBJoO57 RwCrEIx1/BJ1t0o9N7joD6ZOAjxrpqnAZvqZqoC8+oMuf5uYLWdqjaHqFuK7tT3V0U7e Ly5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=UpGVnXwc; 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 r198-20020acaa8cf000000b003784baa9938si6625508oie.134.2023.02.04.19.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Feb 2023 19:01:16 -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=UpGVnXwc; 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 E04F08581D; Sun, 5 Feb 2023 04:01: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="UpGVnXwc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 91A1985821; Sun, 5 Feb 2023 04:01: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-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) (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 E2411857F5 for ; Sun, 5 Feb 2023 04:01:04 +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-ot1-x32b.google.com with SMTP id v24-20020a05683011d800b0068bdd29b160so2414890otq.13 for ; Sat, 04 Feb 2023 19:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=83cyYLXLCt69D00PHCY8u+JaTb2r4DGw8zNIJhejsI0=; b=UpGVnXwcDiEn0VmjbPl7iXp8h4+tcCsIaZg2P1HvP6stVkkyQeoC8tdeUCjoX0VuHp w9tBOCnjahKqs5EAnWVWzeHPP5Wb0mFUCLG2D43ArB9n3IafpOv2o6/xcPvXgXZ+bK2U kr/O4Fds470Mjx4MJcDDk28hnHToNp2UeKmakW+BWkG9LXI3x8CElc+C/RfTNxdD+cxN pmTWHBySJNBUEQqRxW5kt/4SaJtVmRdxxc5/tGsIGxfm5Fa51G0FHIvNp3g1z3yso3w0 B7zJHNsaduMGqZvI5c7jYl1oM7G1Vn/KYslBRTcOwisFFmkG/6gziUNzDKd1brwJ1ElW Deng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=83cyYLXLCt69D00PHCY8u+JaTb2r4DGw8zNIJhejsI0=; b=Lfa76F+eCgRVSqqChcQdu/dKhtYLUQtk2ficGXyYIihEnyniA4kfDP8SOuqDfWU9JX fGki/U8nnqvO8WuAu7oemJyNLGfpucI0il13gsHSTKg4k/bZJqzSuNraFHH9FkpyFlmb 4tpfjdAX8uKSmyLcUB7qAPwcinOd70cIYEnBuKuxKyQJ56siYtb3Ut1nYy1SuJFYhpc4 7PdrdZSc6LDIAkmB1K8vm38N0kSkiHv+n1KCV5YQryXn/eKlOpcJGF5DeB/AUdCz7mTr 661Ojw23SevLudNVsmhXtjNIPiHoZMxLfYuJerbmS6jUgx5auAtzjdgQQ6KiyMqpaW2e ykdA== X-Gm-Message-State: AO0yUKVoY4+YhXPcjxF00xgcBXJ9LUif4VLyAXnRuoJHsRmp3fQYL+Hk pW01H6+KfHwJ+WiCAL6Ia5GuvI7nolw= X-Received: by 2002:a9d:65cf:0:b0:68b:cd6a:4117 with SMTP id z15-20020a9d65cf000000b0068bcd6a4117mr7599975oth.5.1675566063117; Sat, 04 Feb 2023 19:01:03 -0800 (PST) Received: from jassi-Alienware-x17-R2.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id h13-20020a9d6f8d000000b0068657984c22sm3039996otq.32.2023.02.04.19.01.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Feb 2023 19:01:02 -0800 (PST) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de Cc: ilias.apalodimas@linaro.org, etienne.carriere@linaro.org, trini@konsulko.com, sjg@chromium.org, sughosh.ganu@linaro.org, xypron.glpk@gmx.de, patrick.delaunay@foss.st.com, patrice.chotard@foss.st.com, Jassi Brar Subject: [PATCHv4 0/5] FWU: Handle meta-data in common code Date: Sat, 4 Feb 2023 21:00:56 -0600 Message-Id: <20230205030056.61345-1-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.34.1 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 The patchset reduces ~400 lines of code, while keeping the functionality same and making meta-data operations much faster (by using cached structures). Issue: meta-data copies (primary and secondary) are being handled by the backend/storage layer instead of the common core in fwu.c (as also noted by Ilias) that is, gpt_blk.c manages meta-data and similarly raw_mtd.c will have to do the same when it arrives. The code could by make smaller, cleaner and optimised. Basic idea: Introduce .read_mdata() and .write_mdata() in fwu_mdata_ops that simply read/write meta-data copy. The core code takes care of integrity and redundancy of the meta-data, as a result we can get rid of every other callback .get_mdata() .update_mdata() .get_mdata_part_num() .read_mdata_partition() .write_mdata_partition() and the corresponding wrapper functions thereby making the code 100s of LOC smaller. Get rid of fwu_check_mdata_validity() and fwu_mdata_check() which expected underlying layer to manage and verify mdata copies. Implement fwu_get_verified_mdata(struct fwu_mdata *mdata) public function that reads, verifies and, if needed, fixes the meta-data copies. Verified copy of meta-data is now cached as 'g_mdata' in fwu.c, which avoids multiple low-level expensive read and parse calls. gpt meta-data partition numbers are now cached in gpt_blk.c, so that we don't have to do expensive part_get_info() and uid ops. Changes since v3: * Fix error log wording * call fwu_write_mdata() with part & PRIMARY_PART ? true: false Changes since v2: * Drop whitespace changes * Fix missing mdata copy before return Changes since v1: * Fix typos and misc cosmetic changes * Catch error returns Jassi Brar (5): fwu: gpt: use cached meta-data partition numbers fwu: move meta-data management in core fwu: gpt: implement read_mdata and write_mdata callbacks fwu: meta-data: switch to management by common code fwu: rename fwu_get_verified_mdata to fwu_get_mdata cmd/fwu_mdata.c | 17 +- drivers/fwu-mdata/fwu-mdata-uclass.c | 151 +------------- drivers/fwu-mdata/gpt_blk.c | 175 +++++----------- include/fwu.h | 198 ++---------------- lib/fwu_updates/fwu.c | 294 +++++++++++---------------- 5 files changed, 207 insertions(+), 628 deletions(-)