From patchwork Thu Jul 14 18:39:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 590387 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp1849537max; Thu, 14 Jul 2022 11:39:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sCqHuafqntm10hCPkzw3cmyK/fFij5Oqg+QBmtlR/3Y0hadNbwRvQxNM/aY8NQG2TxNV3F X-Received: by 2002:a05:6638:4789:b0:33f:7587:6d64 with SMTP id cq9-20020a056638478900b0033f75876d64mr5562558jab.159.1657823993240; Thu, 14 Jul 2022 11:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657823993; cv=none; d=google.com; s=arc-20160816; b=ylS6QPYYxYjraYg98HsaOI02Vxwf2JAiTdqAlS6MFINQ49TaFEesPhE9Gc2EXp5wRS DLegEF6IjFL8gx22TUHvalqsUkmvquuruMQcIh3nSntCI4D+HHPWKesThtYJcVg2Hy2h Ur+LngRxDf0u4u+CxXhSiNqbnVDT7S44Mp+ruEQDbuqfj8NFvK3u3D6XvNNcamLI6+5L aEWT/2LH5HJd+HMdfjuSfN43pjQLHV7mxaTcxzwRYkAI+sbkzU8bZJrGHdRVvuSIpILf 1p1sAOr1Czxra1UaHyPaW3w+8qjFwMbY6tGLpnopoaW0HXEk6XKk97q1TREQanUJhK2M 7NAA== 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; bh=ft34WL29l+gNww72bgvYhR/xpAU3Dxj1f87mRmYRZPw=; b=V3o+S4yJWQGODErREDQOCRK6SeS6koA7Gvtqx3gdfCMwzd91KkZ7NHGULrSVgcfmR4 BtLuSUCacWifE8ojGj0HBXGzT7zXGz84KoBjozqT0mCbDNXh+bMYRtieIcSudc74Cpi+ GM0kmARBscZAmuk7eTd58p0jj13l9D+6MJ7cU6IsOki7BGflSuQ6WSMphZYFXrRaINKI kjrakOFyljsog4BkbToS+pYn9xQMwat26LsVHfMQN/Jb0HXHfrFB4Hua7wnLf9jK0/9w vV61idGvvxXClrrJSjZnvVGvjlNKk2v7UyqtHJxdTvzNem2w5Fbz3fpZqbkuefANsL/8 Qqsw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 o22-20020a02b816000000b0033ea1f5a473si2217852jam.145.2022.07.14.11.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 11:39:53 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CA10484055; Thu, 14 Jul 2022 20:39:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 8A33784044; Thu, 14 Jul 2022 20:39:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 41A1683F81 for ; Thu, 14 Jul 2022 20:39:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C11DA1D13; Thu, 14 Jul 2022 11:39:42 -0700 (PDT) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0E1E93F70D; Thu, 14 Jul 2022 11:39:38 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Takahiro Akashi , Patrick Delaunay , Patrice Chotard , Simon Glass , Bin Meng , Tom Rini , Etienne Carriere , Michal Simek , Jassi Brar Subject: [PATCH v7 00/13] FWU: Add FWU Multi Bank Update feature support Date: Fri, 15 Jul 2022 00:09:00 +0530 Message-Id: <20220714183913.118505-1-sughosh.ganu@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 adds support for the FWU Multi Bank Update[1] feature. Certain aspects of the Dependable Boot[2] specification have also been implemented. The FWU multi bank update feature is used for supporting multiple sets(also called banks) of firmware image(s), allowing the platform to boot from a different bank, in case it fails to boot from the active bank. This functionality is supported by keeping the relevant information in a structure called metadata, which provides information on the images. Among other parameters, the metadata structure contains information on the currect active bank that is being used to boot image(s). Functionality is being added to work with the UEFI capsule driver in u-boot. The metadata is read to gather information on the update bank, which is the bank to which the firmware images would be flashed to. On a successful completion of the update of all components, the active bank field in the metadata is updated, to reflect the bank from which the platform will boot on the subsequent boots. Currently, the feature is being enabled on the STM32MP157C-DK2 and Synquacer boards. The DK2 board boots a FIP image from a uSD card partitioned with the GPT partioning scheme, while the Synquacer board boots a FIP image from a MTD partitioned SPI NOR flash device. This feature also requires changes in a previous stage of bootloader, which parses the metadata and selects the bank to boot the image(s) from. Support has being added in tf-a(BL2 stage) for the STM32MP157C-DK2 board to boot the active bank images. These changes have been merged to the upstream tf-a repository. The earlier patchset contained patches for both the DK2 and the Synquacer platforms. The handling of review comments for the Synquacer platform is to be taken up by a different engineer, and has not been done yet. After discussion with Tom Rini and Heinrich, it was decided to send the patches for the DK2 platform separately for review. The patch for adding a python test for the feature has been developed, and was sent in the version 5 of the patches[3]. However, the test script depends on adding support for the feature on MTD SPI NOR devices, and that is being done as part of the Synquacer patches. Hence these set of patches do not have the test script for the feature. That will be added through the patches for adding support for the feauture on Synquacer platform. [1] - https://developer.arm.com/documentation/den0118/a [2] - https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf [3] - https://lists.denx.de/pipermail/u-boot/2022-June/485992.html Changes since V6: * Define the LOG_CATEGORY macro as suggested by Patrick * Add some documentation in the fwu_get_mdata and fwu_update_mdata functions to describe the sequence of calls to be made for modifying the metadata, as suggested by Etienn * Define the LOG_CATEGORY macro as suggested by Patrick * s/STM32MP1/STM32MP15/ as suggested by Patrick Sughosh Ganu (13): dt/bindings: Add bindings for FWU Metadata storage device FWU: Add FWU metadata structure and driver for accessing metadata FWU: Add FWU metadata access driver for GPT partitioned block devices stm32mp1: dk2: Add a node for the FWU metadata device stm32mp1: dk2: Add image information for capsule updates FWU: stm32mp1: Add helper functions for accessing FWU metadata FWU: STM32MP1: Add support to read boot index from backup register FWU: Add boot time checks as highlighted by the FWU specification FWU: Add support for the FWU Multi Bank Update feature FWU: cmd: Add a command to read FWU metadata mkeficapsule: Add support for generating empty capsules mkeficapsule: Add support for setting OEM flags in capsule header FWU: doc: Add documentation for the FWU feature arch/arm/dts/stm32mp157c-dk2-u-boot.dtsi | 7 + arch/arm/mach-stm32mp/include/mach/stm32.h | 5 + board/st/stm32mp1/stm32mp1.c | 67 +++ cmd/Kconfig | 7 + cmd/Makefile | 1 + cmd/fwu_mdata.c | 80 +++ common/board_r.c | 5 + doc/develop/uefi/fwu_updates.rst | 156 ++++++ doc/develop/uefi/index.rst | 1 + doc/develop/uefi/uefi.rst | 2 + .../firmware/fwu-mdata.yaml | 32 ++ doc/mkeficapsule.1 | 33 +- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fwu-mdata/Kconfig | 16 + drivers/fwu-mdata/Makefile | 7 + drivers/fwu-mdata/fwu-mdata-uclass.c | 469 ++++++++++++++++++ drivers/fwu-mdata/fwu_mdata_gpt_blk.c | 410 +++++++++++++++ include/configs/stm32mp15_common.h | 4 + include/dm/uclass-id.h | 1 + include/fwu.h | 71 +++ include/fwu_mdata.h | 67 +++ lib/Kconfig | 6 + lib/Makefile | 1 + lib/efi_loader/efi_capsule.c | 231 ++++++++- lib/efi_loader/efi_setup.c | 3 +- lib/fwu_updates/Kconfig | 31 ++ lib/fwu_updates/Makefile | 7 + lib/fwu_updates/fwu.c | 191 +++++++ lib/fwu_updates/fwu_gpt.c | 88 ++++ tools/eficapsule.h | 8 + tools/mkeficapsule.c | 105 +++- 32 files changed, 2094 insertions(+), 21 deletions(-) create mode 100644 cmd/fwu_mdata.c create mode 100644 doc/develop/uefi/fwu_updates.rst create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata.yaml create mode 100644 drivers/fwu-mdata/Kconfig create mode 100644 drivers/fwu-mdata/Makefile create mode 100644 drivers/fwu-mdata/fwu-mdata-uclass.c create mode 100644 drivers/fwu-mdata/fwu_mdata_gpt_blk.c create mode 100644 include/fwu.h create mode 100644 include/fwu_mdata.h create mode 100644 lib/fwu_updates/Kconfig create mode 100644 lib/fwu_updates/Makefile create mode 100644 lib/fwu_updates/fwu.c create mode 100644 lib/fwu_updates/fwu_gpt.c