From patchwork Mon Mar 6 23:17:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 659269 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp2084948wrb; Mon, 6 Mar 2023 15:18:11 -0800 (PST) X-Google-Smtp-Source: AK7set8zcXByg9UqTWVoqPchTP4glCEFOYh93CqFfUbzdbZs78aU8SrYP6+i7IdNa4N4pPlu0ujx X-Received: by 2002:a5d:4569:0:b0:2c7:6a6c:c71e with SMTP id a9-20020a5d4569000000b002c76a6cc71emr8499870wrc.70.1678144690246; Mon, 06 Mar 2023 15:18:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678144690; cv=none; d=google.com; s=arc-20160816; b=xDQEgsrZNa7XQsc+m/dCLwnG5xMIueXm4YUH6do4yMQ06acDyakZFMHx9cDFNAMxWy k9dxg57rqdNPxDipAV7TgqZT90XBjBTWg9U7HhAFA8yLDGl+TPjckAzJAfdHsAu+OX96 H2m1G65Exva+KHNe0b1hBmUmcdDwcGigq+y/Jk21Wi0+yTypOkmCK/MAKpYuNg2G7Ydk u+f5F+DdDermtwOJfhtqqhRIKUPzya/975zeBvN9fRuPWRGVMt9U+nPb5ch6QZI4RG52 3q0x+xvGY0dEBTX94v9tEcrUaAyUbKOTUjH2xkr7Sq5JR0ASW2HBHR/PKe2SffJvsKv2 /EyQ== 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=hY6nCxWQfA5r5GBnAlmcSkveaqABR56PNP8Nx2R2vKM=; b=zn5T7qNBr6GyBDAIq4gwVFUQTnLBjnv9y0uyjrk633yjenlA1l0YkR3uyHwSVZCaDA xzb1hHy+GeShPH2tOqn/2pslbCCHPGcfTG/iYQfLTYLAcBDBrJEFQm5KBwHbwnXlh75O wFQEEaqZ4ZvA2cLIoCwZezDFAQoorfCLoAIzZVoNLzanPSf6JsS0l+6CHWt/y2yZyZbG BdHEmaHLdNJ2OT/Er7SMmRP+u1ggX8351wM5bpV+avpZHl18dCRFRkx2tPsvZz9Ia4GG su9h4Q4OrLfq4q6CggCWz4fbOfMG/t/21K51EKNOiaREDCPiJEHpTbrzcE/6n/MjLRge Db/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EhUSEXl4; 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 x16-20020a5d4910000000b002c55a69f798si9293886wrq.391.2023.03.06.15.18.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 15:18:10 -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=EhUSEXl4; 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 2635F85359; Tue, 7 Mar 2023 00:18: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=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="EhUSEXl4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EF1F580BAF; Tue, 7 Mar 2023 00:18:00 +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-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) (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 CBB79858B8 for ; Tue, 7 Mar 2023 00:17:55 +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-qv1-xf34.google.com with SMTP id nv15so7825659qvb.7 for ; Mon, 06 Mar 2023 15:17:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678144674; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hY6nCxWQfA5r5GBnAlmcSkveaqABR56PNP8Nx2R2vKM=; b=EhUSEXl4vSM4YX4b45wYKcUURwjqQ/JtZ8hbAAbblJogDqET+WykRRVhLUPC0ipSbo xMJH61MAjxW1RYFN0BCsyXHOtWUx+7VQObpYiR3+HKPYcjOWDhjZL+2LK5hX0k7gOTz5 bL5Dzi+H8AG//MyjGzd2eAPg6Zs4DqbsqCBOm7LP2u6TpY2FUhLkOYM+5KnBY40YPhQM Cn/1mchWq5F3AD7TtHHEbMHPGSK3lVihLh7jyj5EAZftUSHoh+EmK11LS9a/zg90cAVS RIwcLJZ4q/uoAKLE2TlcvCh6/NONivKUJEyZySc/BKWnuf9f+59zkQJCAs46lLxcpzZU nQvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678144674; 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=hY6nCxWQfA5r5GBnAlmcSkveaqABR56PNP8Nx2R2vKM=; b=Iemge6ZMLy4RpRah4xjO+D1a2nJ0q7Ir6ctSwtoQ8MfMyUvLAM6XoiryiQKWA1P+mg yhBdqSOxTLVgtDZW/prQT+La+eqplKLAFk6KGCiUbe9ePfHAoziIM/mgpAd/W+f3xRms x2Ll0NvSl3M+gaDh/MBxk8Oz1yv+Hgn61VN78pxIjvxNvjEbqhAat7GoPzKPsjjlij+t G9uVF1CjQsUjGNCF0+zntTTawrqoHTTGbLrccvB5WEpnk41kFaaCrTQAr/ZVALrP9/3E fwpTmRfTZIbhtPOouUioJYISt96FOZdu9AMJ9Sttq/sixjSKwIcVsgdevKEjSbnoLeTF pcZg== X-Gm-Message-State: AO0yUKUgwTil/6ssbqDO4tq0QNzv+xvaZ0nKvnCqeZIWnGSod4RfJtzW Bhz7HCExA1whQiMX7iZYPvMTc0/+qeA= X-Received: by 2002:a05:6214:d0e:b0:571:314:d725 with SMTP id 14-20020a0562140d0e00b005710314d725mr21343101qvh.49.1678144672159; Mon, 06 Mar 2023 15:17:52 -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 d15-20020a05620a240f00b00742562938cfsm8670580qkn.107.2023.03.06.15.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 15:17:51 -0800 (PST) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de Cc: ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, etienne.carriere@linaro.org, trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, patrick.delaunay@foss.st.com, patrice.chotard@foss.st.com, Jassi Brar Subject: [PATCH v6 0/7] fwu: gpt: implement read_mdata and write_mdata callbacks Date: Mon, 6 Mar 2023 17:17:47 -0600 Message-Id: <20230306231747.1888513-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.8 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 v5: * Fix SANDBOX tests * Removed '@' from dt nodes * misc cosmetic changes suggested by Etienne 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 (7): 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 test: dm: fwu: fix for the updated api 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 | 296 ++++++++---------- test/dm/fwu_mdata.c | 22 +- 7 files changed, 299 insertions(+), 665 deletions(-) Tested-by: Sughosh Ganu