From patchwork Tue Feb 28 00:51:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 657464 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1b90:b0:222:2e2e:b2c3 with SMTP id e16csp3401370lty; Mon, 27 Feb 2023 16:51:50 -0800 (PST) X-Google-Smtp-Source: AK7set8bVMiD3r0UeVVQgXIwdeSmO1+A55nGEdeC5SSOVWp4MqdEVrDTsTawjy4cBLvCkPYFHi9M X-Received: by 2002:a17:903:2308:b0:19d:16ed:3e34 with SMTP id d8-20020a170903230800b0019d16ed3e34mr1110732plh.26.1677545510729; Mon, 27 Feb 2023 16:51:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677545510; cv=none; d=google.com; s=arc-20160816; b=pEXVUNr1Jc43wZQCKj8Jp+K17HyJUpwzXmB00/s8wJb6L2Ef93xa+X2C6g+7CcBQ3U 6qJ84qoLenCMMY5c/uwSn/Ewh75oEBfgLPO2Xtzc7NuAF1ahTrtXApdQi4vQQcpLlivW tt3buTV5tw6rG/O6W2jv3NMJRgeUtLPq8ZYPQhjOhJwlax3mM8rnmtjKsdyICaN74Ksd 10lPhjoATVTlSmqJM7mFO/OJaCs//hY/H7pDfVzMH8L5s6dmuHIf/fm9VHDBWHY/Mctb RKeK0oM61mjzufUwipPtxcbB2pi0O9UINBlSG/6YVWXWZYmd7ZmXPwz2Jp2lcUlZ8FF4 6jhQ== 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=P4jaZAIU9559q5F4UxlleqdW36p2LaGOn/ijwOYa41A=; b=b8a9/bjwrR4yIzvHUOAN6bv3yHa8SC2VUhVuj+QNY76FJvyrG7ds0HCEnpMZbxnm7h K8qbJUUgQLsOsQLtjgAaS2elN2ViF6jNWgEHPd0XmoKqVkjuoLsfaf2d5+axW2yxkliV i/2+zy8qWXvXu3EkpbGM+LbM/7HNnhlmGHVj1EZguYMiA9otFaZ5i2mxO83RVgUBFHL1 8aWngRN4SLL8G66Zx1De26L2ysFSF3++5FrrULwQSqkkpzdBitpAWDZ6ZG4q4W+HkQlA Blp/KQdzJvoDcWLbCrZUibgddV+jyEOORttMyvrTEZk8gUjwdh16GQ0UbC/JkWW6Kzwf KxZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nv6aEp07; 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 kl12-20020a170903074c00b0019ce503d057si7614071plb.519.2023.02.27.16.51.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 16:51:50 -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=nv6aEp07; 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 711C7856C0; Tue, 28 Feb 2023 01:51:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nv6aEp07"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9020485757; Tue, 28 Feb 2023 01:51:44 +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-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) (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 170688514E for ; Tue, 28 Feb 2023 01:51:42 +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-x12a.google.com with SMTP id u6so5391284ilk.12 for ; Mon, 27 Feb 2023 16:51:42 -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=P4jaZAIU9559q5F4UxlleqdW36p2LaGOn/ijwOYa41A=; b=nv6aEp07d8kFIoukwMKjdwUAqljM+1q/E+CWd3y88BbbrIJGmWwP9094xDxnJLwapi nr9DdNHE3vOUGxI645DkLaXxFxnUI1TI0Bi06quNbxioFY6kI1YEtUwDj5AOnnvRhlUb v8SL1xBcgeL8cPG/pT1IlxT/oMoaB5pFi9nVV+EuFTlMoscWnoup+TjkkAlD/J4BKS1b ZehE6IeD397g6unLyVmE6qv16QFwzokxGOYCN/EKBTz1NyjjgKipcZn1zh/z76F30BxA RLtLHyvt+Tu5iWX0M9pak0lpMfoRr4ZUmJc99xzLnFbFBSTDMDulxwHSYp8jHIYhUGjG TJ5w== 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=P4jaZAIU9559q5F4UxlleqdW36p2LaGOn/ijwOYa41A=; b=CaChSTHZqISfgRKhaXCVzyGptQQvf9hrPssb5blLCPznp9fuu/4J4hrKmgln8jKNqn FPGV1wI0wbBt53JXJ8VVj5jH1wRNF6MRs3T1GPtBZpbuZSMSdEucZEYJ4BA3NGL99cpi QyROFsvbttCNf2R/3clLBMH1eZH1/ECFGnNFxPRsrBaylodUddcGvqCbwgSV9dnVY758 8gfRgigx4Qj9MVvtJ14gA3uY55Enc9bAGDnQFFGD7oooJJFNmukk2gU73O46mJAB7ycl Z4KpkF5ZR9flB4HIz81Y0OeJHpDzHqVOOhk57uRU2PUZd5Wb618x4hHCtoFefvFTUhm7 QeRg== X-Gm-Message-State: AO0yUKUWZ1mdQ1Tt5eBs863PLe8yD+KzAae5va9i+Cuv88sVE4VId8Lu Iu62RzNHyCbqo8Ws9kszAA2dIAgHSd8= X-Received: by 2002:a92:b50e:0:b0:316:e39f:144c with SMTP id f14-20020a92b50e000000b00316e39f144cmr976778ile.2.1677545500369; Mon, 27 Feb 2023 16:51:40 -0800 (PST) Received: from jassi-desktop.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id e15-20020a02a78f000000b0039e68e9988csm2414068jaj.56.2023.02.27.16.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 16:51:39 -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: [PATCH v5 0/6] FWU: Handle meta-data in common code Date: Mon, 27 Feb 2023 18:51:35 -0600 Message-Id: <20230228005135.1635726-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 v4: * Change fwu-mdata-mtd bindings to not require external changes * Handle 'part == BOTH_PARTS' in fwu_sync_mdata * use parts_ok[] and parts_mdata[] instead of pri/sec_ok and p/s_mdata 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 (6): dt/bindings: fwu-mdata-mtd: drop changes outside FWU 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 +- .../firmware/fwu-mdata-mtd.yaml | 105 ++++++- drivers/fwu-mdata/fwu-mdata-uclass.c | 151 +-------- drivers/fwu-mdata/gpt_blk.c | 175 +++-------- include/fwu.h | 198 ++---------- lib/fwu_updates/fwu.c | 295 +++++++----------- 6 files changed, 295 insertions(+), 646 deletions(-)