From patchwork Mon Jan 2 18:25:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 638429 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp942292pvb; Mon, 2 Jan 2023 10:25:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXuVujO2JR5wNHM/W2KJp16riSziwpBcf2uErCVvekhAlZdxVM5l28Rrwh2L3WUKg8F8aLhs X-Received: by 2002:a05:6808:294:b0:35e:30a7:149a with SMTP id z20-20020a056808029400b0035e30a7149amr17232119oic.19.1672683948367; Mon, 02 Jan 2023 10:25:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672683948; cv=none; d=google.com; s=arc-20160816; b=T74cNRNoKKSQhlV+Bj2uRBFL7X3EqUArDRkBB1SbZMibYg1jsGEivBs5hMs0RG2bwc 38FVC+ZLOHv56RuE+vm+MrCe0CPv77S7gXto0AM/yXMTUHdf+4dn602Bc+kvnUkrMtN0 VROv66szp/M4a3TTN2V2xKWgNcEqY2muOyZRE+ByqdzhowzFlKY9P/gzdn8qc6z1b+vg +AGkvz40L8Vya7t6IlGwMZeb34VgWno638+bLEuJjuM+RvdJHggQgCyozFlfHeiBy0Bz Ui9hVhRh5Ls1NjIrYqHknH0qaCFOIIr+2dLLFisWLGbjOdfGvws/VzoWS8eRtkb/sP+8 g6/w== 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=abSuqZFLeDeSbbFkMtst7JVROSHy9aYUh3ecmeb7N5I=; b=UjzI+XmOCo/XLZaiAtqR/vJMbvvLuL5o92EDVfQeQxlXsUbBiDaz+8IHs4jJOxOgPP 8CoylttqDrNkr43MnrGkUKkwYzZkultoRwKxzzNSbcaipuHPzSM5aLDfJh+Bt1fmxl6W YhKXGqjH9tJX+fNbkLx8d+MoZQ6k0gY/JU7KMrlGEcvTBBtQYWKdcsB0xyO6+Uqw099C dFRgxgKvZRGU2mGvyDCy77bjSOQAVrGRMV7AsRHBuFVr0KOzl2u0TqGuMYni63R+IgAM WfjWljaH3qKOVkDGMu9Osw77cB0fU3oIWVpdjPq7zO1bWj2qIfqgIUxX37rmT3l3L+mf B23A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MVNOL3ot; 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 q203-20020acac0d4000000b00359a84554e1si19182273oif.276.2023.01.02.10.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:25:48 -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=MVNOL3ot; 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 10BFA85413; Mon, 2 Jan 2023 19:25: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=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="MVNOL3ot"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 13AA785422; Mon, 2 Jan 2023 19:25: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-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 281D38533F for ; Mon, 2 Jan 2023 19:25:38 +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 a9so4556940ilk.6 for ; Mon, 02 Jan 2023 10:25:38 -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=abSuqZFLeDeSbbFkMtst7JVROSHy9aYUh3ecmeb7N5I=; b=MVNOL3otCwLJRvpm99VoY4IzH7BE69j7uXS84fGQaahcXGcDpmcnLlCG9AxiTJ0Vsp iZVtPwOL0YVLPBCHlQaNBBsBGEauaWfc8shQgeEPNC5LHCIxW5P/JgYwlaSE6+QgvSmz tZG4a/dUUyI3p45OUKTaimBmfEdBH50Ox/E6KjWitp+B7t6WmegfC0I3t3b1JIsI5bdy HfhA3pZY0UTIzSb3dfBKneg9i70pIDuG83t1umKUsAVIH4yNbt/yPQKfz+WORJIpfPrg la+aIv1JSzLzIHe9zBLuSb10HMgmLhGE2DsNYmltm5d3LI9g3y22gOw0NXGMN2vjAF2x Pofw== 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=abSuqZFLeDeSbbFkMtst7JVROSHy9aYUh3ecmeb7N5I=; b=BXekMHfqwLaXsxp/hPonQwonPGMj4R/ogA7lcc7/7EFVglvZsgcpdy7yKfME7y0ww9 1WQo7Ln9ZNEfz0DFbr4DWAOx1jBPrKR9RgYLiwLEMTvY/DmpCjRMrIX0mtYwIGL3/zMV SSv8YfKTIQQIS5kdYnH00UIlZj2Jex/ejZfZwdVb9RMoDpFL7OHV5FHJADbMZG1bXJo3 rhHcID/yDxBdej19zaKaz6pmP7O27SNRbNS19XXurgf0qbejsD+1i2nBODkCnjIhDl3L eC+DZhoe3kyLk5vTHotJt7UYYWh9i2yaRqC1jCo2X8FgI8yWExf0sW/SliNNCQYImakl +crg== X-Gm-Message-State: AFqh2kodxn9OmeT1N4PDhJ2wP2g89iUcmXt8+sX12VNIFRNWBA4zuypC y1UttH45++ji37QZ3YveqMwcUuAELho= X-Received: by 2002:a05:6e02:50b:b0:30c:87a:2804 with SMTP id d11-20020a056e02050b00b0030c087a2804mr17503217ils.29.1672683936430; Mon, 02 Jan 2023 10:25:36 -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 q39-20020a027b27000000b00389fb6c2ca5sm9274772jac.98.2023.01.02.10.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 10:25:35 -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 0/5] FWU: Handle meta-data in common code Date: Mon, 2 Jan 2023 12:25:32 -0600 Message-Id: <20230102182532.2411125-1-jaswinder.singh@linaro.org> 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 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 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 | 301 ++++++++++++--------------- 5 files changed, 214 insertions(+), 628 deletions(-) Signed-off-by: Jassi Brar