From patchwork Sat Dec 3 03:15:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 1711657 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=o5zVFKD+; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NPFMX1KzGz23n4 for ; Sat, 3 Dec 2022 14:16:22 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 117CA85023; Sat, 3 Dec 2022 04:16:10 +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="o5zVFKD+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7096685035; Sat, 3 Dec 2022 04:16:07 +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-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) (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 AA5C984FF0 for ; Sat, 3 Dec 2022 04:16: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-io1-xd2e.google.com with SMTP id z144so7045iof.3 for ; Fri, 02 Dec 2022 19:16: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=Zc/GfUtepKNm/Q7VWwjOsnTgRM1bgOuh3qSY6ulMdGk=; b=o5zVFKD+l8dWqqPvDhTm/GHzOuhkXWxYhm/2l7Fnt5CqGT01njDI0eF5IY5FpUaxda iooRyv3+GA76bd4lM1mkyISChVAvbziF5KR1PwPsPj0LRBm1l6CS5VwwAuPyL/neUCEJ ymAPacy2jychT5VnSgrR5ZgMEhJNPlqRtORurXXFQb9EfZLqsknsusQtCu3KgF+xC/VI giohGnfKByN4lFYRg9yeT+et6rVYVIo3Xz1EqSNYun1D4fD/crE4luJFRs/antkmQJsx fSNkc45A1BUlcVMpFoZ6y8621Phj8arrto9ClsivPcFOBytTI0ezd/C7pRkQQLSMML4z iXhA== 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=Zc/GfUtepKNm/Q7VWwjOsnTgRM1bgOuh3qSY6ulMdGk=; b=OOOPrJIe9dS7ZsM1hzdYSfeIaROrJVxEg1V6dZtvmNC9oEoY+qY5gP1etygri5Hf+V 64NP7QCjwbxb4SaW4mGiEyvuQToOHDya0fYkKxtWoXqQ4zM7MI3+5M9iTwl+7mAwC/nw zqgZbqt7s21kyJB3TmpyDSBOLDVVjrY8mBg6TbiUXYBcbMvUa4ogUVP1oPSAeWMsluhn p5vG6j+BZEnHwHgmZSGtrqYD5WZEasTK8XrlZl/bAouUbSO0hwx0jfVBJogdFsX9YnJY cxQ7pWJAAzRHv/1oolg27xOXlhYcLsGblW6nUay/OnIPyUx6CPhe2PFMBE91Hj6GJJVq GuTA== X-Gm-Message-State: ANoB5pluLZKIcu86JVH9WMqdgZUC3k7XOMaAugZljhqkM5tECKg0jZYI qfMIYPWFK/wGQVLtHN0h677K5p9jSzc= X-Google-Smtp-Source: AA0mqf4fAoJ+pH95Om3lYAVj3O8IFUS9G9pjTwUy5ZxvbYrEtoLI8PmhB4U7p2U4iF1bjaUBCBmGAQ== X-Received: by 2002:a05:6638:263:b0:376:26c3:fcd7 with SMTP id x3-20020a056638026300b0037626c3fcd7mr25111898jaq.280.1670037362791; Fri, 02 Dec 2022 19:16:02 -0800 (PST) Received: from jassi-desktop.. (wnpgmb0311w-ds01-45-179-115.dynamic.bellmts.net. [206.45.179.115]) by smtp.gmail.com with ESMTPSA id l19-20020a6b7513000000b006bb5af55ddfsm3248203ioh.19.2022.12.02.19.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 19:16:02 -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: [PATCHv2 0/4] FWU: Handle meta-data in common code Date: Fri, 2 Dec 2022 21:15:57 -0600 Message-Id: <20221203031557.579632-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 v1: * Fix typos and misc cosmetic changes * Catch error returns Jassi Brar (4): 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 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 | 300 ++++++++++++--------------- 5 files changed, 214 insertions(+), 627 deletions(-)