From patchwork Mon Feb 7 18:19:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 540565 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp344104imr; Mon, 7 Feb 2022 10:21:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmk06ofWkrbg04w0mXZOdMXoaAUGPzds135DpS0uhoSfbYD2Nx4amgctA871Lac9AIqV4Q X-Received: by 2002:a50:f18c:: with SMTP id x12mr735106edl.426.1644258070113; Mon, 07 Feb 2022 10:21:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644258070; cv=none; d=google.com; s=arc-20160816; b=NUVcuwxZfGT26zCkxy/4SjV6wWMA2rWu3nMG293sVTdccGJsLpmSs1xq8zv+aNHqL0 Uce/Gn+WMknC0IMuuvxFfpqvdwsv2F5clle4mpPZa9ar2buCZBv1i8fvYEaAp5TyXMuu WQJ/Qa5a7fCkmHNAjFxbcvsoGZRfA7N44EyUUd0qw4oRcyK3hgkQKo99F61bD1aC1PBV E2AIPgw2clRwU0XhNXCDfG3yoaVvsB7ubOQgm+5IOld2rlcvpvfkMx/2+NMpkMcPwpuj J8DWZKOHU4XV5ztVHNUDcIyj4XCg71+Lb8eO7Ws1gDrGk6LVb5TvE7fqFbAVoMFZVTLp MdNg== 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:message-id:date:subject:cc:to :from; bh=yE7CrHfuIQGAG9QSodfEfLujBBjaMAJEe/Hanbp1vLw=; b=OB9XRrfTb08Xm3wpnf1lB+0ULGHrBsWzMH4d3Bo7D3r/0RDF1ybzlBnEStpMiNoNCy iMmQr8rg8sxRMwBDwtLPpz8pc8Hj29jxI34hgVprxlmGUaaVDcX8nQR36GCi8S2NF2WH ZTR3TE6srJcOoxxRECdI1FHa9QzOXT5pZnSh7SNvPQr5EPfJiseetI2Bmzpj4c9rTm+l EqSdXQkcEhGaiy16fGysIoSHyAUl7ymQp4pAuS8vwcub9qHDMtXwr6f/NHaFPhbamKOJ SUkC0U8KaQgHo6I1Ekq9CI01kYjNsGnMKkHQjoOii6WAGTo8iFFhYNLAQCe812YmKR0q I1tw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id qa11si2440653ejc.415.2022.02.07.10.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 10:21:10 -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; 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=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 ED24E83059; Mon, 7 Feb 2022 19:21:08 +0100 (CET) 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 A613083835; Mon, 7 Feb 2022 19:21:06 +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=-1.2 required=5.0 tests=BAYES_00,LOTS_OF_MONEY, 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 C8D7983055 for ; Mon, 7 Feb 2022 19:21:01 +0100 (CET) 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 B57BB11B3; Mon, 7 Feb 2022 10:21:00 -0800 (PST) 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 EC09F3F718; Mon, 7 Feb 2022 10:20:56 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere Subject: [PATCH v4 00/11] FWU: Add support for FWU Multi Bank Update feature Date: Mon, 7 Feb 2022 23:49:50 +0530 Message-Id: <20220207182001.31270-1-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 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.5 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 board which boots a FIP image from a uSD card partitioned with the GPT partioning scheme. This also requires changes in the previous stage of bootloader, which parses the metadata and selects the bank to boot the image(s) from. Support is 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's integration branch[3]. These patches are based on top of the series from Takahiro to add Authentication support to mkeficapsule utility[4] and a couple of other patches[5][6] TODO's ------ * Add a unit test case for the newly added FWU_MDATA uclass. Some involved effort is needed on this since the host device interface on sandbox cannot be used with the UT framework. * Add test case for the feature with the python test suite, along the lines of capsule update testing. [1] - https://developer.arm.com/documentation/den0118/a [2] - https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf [3] - https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/log/?h=integration [4] - https://patchwork.ozlabs.org/project/uboot/list/?series=281549 [5] - https://patchwork.ozlabs.org/project/uboot/patch/164388019634.446835.18271480521485569016.stgit@localhost/ [6] - https://patchwork.ozlabs.org/project/uboot/patch/20220129192108.6618-1-sughosh.ganu@linaro.org/ Changes since V3: * Move the FWU metadata access to driver model * Get the storage device containing the metadata from a device tree property instead of a platform helper function * Move the metadata access driver for GPT partitioned block devices under drivers/fwu-mdata/ directory, complying with driver model. * Move functionality to get the active index under the common function instead of the GPT block device specific driver. * Remove function for getting the storage device containing the metadata as the information is now obtained from the device tree. * Define a weak function fill_image_type_guid_array for populating the image descriptor array with u-boot's raw and fit image GUIDs * Define the function fill_image_type_guid_array for the ST DK2 board for GPT partitioned devices. * Change the TrialStateCtr efi variable attribute to remove the runtime attribute * Rebase the change on top of the patch from Masami to call efi_capsule_update_firmware directly. * Put the FWU related checks which were earlier in efi_update_capsule function to separate functions fwu_empty_capsule and fwu_empty_capsule_process. * Use the device model api uclass_get_device to probe and get the FWU Metadata device. * Add related documentation for empty capsules in the mkeficapsule man page. * Add separate usage for empty capsules, with corresponding valid options. * Use ternary operators where possible. * Put a exclusivity check for the empty capsule options. Sughosh Ganu (11): FWU: Add FWU metadata structure and driver for accessing metadata FWU: Add FWU metadata access driver for GPT partitioned block devices FWU: stm32mp1: Add helper functions for accessing FWU metadata FWU: STM32MP1: Add support to read boot index from backup register EFI: FMP: Add provision to update image's ImageTypeId in image descriptor stm32mp1: Populate ImageTypeId values in EFI_FIRMWARE_IMAGE_DESCRIPTOR array FWU: Add boot time checks as highlighted by the FWU specification FWU: Add support for FWU Multi Bank Update feature FWU: cmd: Add a command to read FWU metadata mkeficapsule: Add support for generating empty capsules FWU: doc: Add documentation for the FWU feature arch/arm/dts/stm32mp157c-dk2-u-boot.dtsi | 7 + board/st/stm32mp1/stm32mp1.c | 178 +++++++ cmd/Kconfig | 7 + cmd/Makefile | 1 + cmd/fwu_mdata.c | 74 +++ common/board_r.c | 6 + doc/develop/uefi/fwu_updates.rst | 142 +++++ doc/develop/uefi/index.rst | 1 + doc/develop/uefi/uefi.rst | 2 + .../firmware/fwu-mdata.txt | 18 + doc/mkeficapsule.1 | 23 +- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fwu-mdata/Kconfig | 16 + drivers/fwu-mdata/Makefile | 7 + drivers/fwu-mdata/fwu-mdata-uclass.c | 434 +++++++++++++++ drivers/fwu-mdata/fwu_mdata_gpt_blk.c | 501 ++++++++++++++++++ include/dm/uclass-id.h | 1 + include/efi_loader.h | 2 + include/fwu.h | 70 +++ include/fwu_mdata.h | 67 +++ lib/Kconfig | 6 + lib/Makefile | 1 + lib/efi_loader/efi_capsule.c | 221 +++++++- lib/efi_loader/efi_firmware.c | 71 ++- lib/efi_loader/efi_setup.c | 3 +- lib/fwu_updates/Kconfig | 31 ++ lib/fwu_updates/Makefile | 6 + lib/fwu_updates/fwu.c | 204 +++++++ tools/eficapsule.h | 8 + tools/mkeficapsule.c | 131 ++++- 31 files changed, 2208 insertions(+), 34 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.txt 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