From patchwork Sun Dec 19 07:05:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 525849 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp3052883imb; Sat, 18 Dec 2021 23:06:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzH61kONr2o8IHGztxoAcGtpkuGlbX2fboR0f3tWUXiS0WX1Xa21EFbygvzOMoL+TCj6Oc/ X-Received: by 2002:a17:906:3a12:: with SMTP id z18mr9010186eje.755.1639897596705; Sat, 18 Dec 2021 23:06:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639897596; cv=none; d=google.com; s=arc-20160816; b=ugZslsVMRBKWqYBNu4+WLIhP5ddw2QWjnzO655knzAzfdEItOle0wQHZAJ+wzUjWdp PyIqNtHPaaErufztuJRrCix+PD6N3LVCMKvrieAxCoKGEYDXYNvy7Ji7OGQMHJwTa6Pf +S5xGEhCUJiJEGDX+oqwTeEJn2sE6I4VYtFIR87mD86kM8+8JYRJ4Z509Nz7pfXpFZDx VG1la1ejv7LcbWSSs/nIdhyYLhuSnm88EoCtDtsYGj5CBAIQqhglu79SSmnCJuTO/em4 GjzSE3XjtmCAvVF4g+fcErbF3ADP83iVmB+yeTOWimdiWW3EbPL6zj0/aM60NzyYvJmJ NJNA== 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=3HqV93uPRDDqWmj14RdEp1p1LaVJf0F06e5NDm+v73E=; b=hI4Wf3ad8mubpTwzV7r+r33A7O0iOIvmyWR0Nzics7Ht1lc/bsa8TuQuZUxKv9P4jG iXo/cxExXWFS/fqHLjRS+74ObDyXTRCGGLHHKE2GOA3Nh7oGv4hzaeL12y1Ih1bbW9eY /sCgtbDbrOQGM09hBoGUH5+Uz4ggy+d9IpgVccei4Z+Qa+4BMEYpJyh1GV6ZnPBb6+5u KvefLdk6LRJxZbp2zBEcORJDfJJ/vO7G1FfCw9er63Tdkpa8n5TSCs6LYzRt08c4g2a7 VG8Q/2z93AteTOrRJ7s+2YqhBRqsTrSRKaIBf1MroCOZhxt96g0W7OA2u6ah6TDHUjam kFEA== 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 c6si7527623eje.774.2021.12.18.23.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 23:06:36 -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 CA7EC83028; Sun, 19 Dec 2021 08:06:32 +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 15EF982FE0; Sun, 19 Dec 2021 08:06:31 +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 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 CD42182F95 for ; Sun, 19 Dec 2021 08:06:26 +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 E409C11B3; Sat, 18 Dec 2021 23:06:25 -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 264AF3F5A1; Sat, 18 Dec 2021 23:06:21 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Jason Liu , Tom Rini , Etienne Carriere Subject: [RFC PATCH v2 0/8] FWU: Add support for FWU Multi Bank Update feature Date: Sun, 19 Dec 2021 12:35:57 +0530 Message-Id: <20211219070605.14894-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.38 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.2 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 are under review currently[3]. Changes since V1: * Rename metadata with mdata for all symbols. Applicable for all patches * Move all function declarations to a separate header fwu.h * Drop the patch which added the get_gpt_hdr_parts api, as suggested by Patrick * Use the logic suggested by Patrick to get the partition type guids and partition guid's instead of defining a new api * Drop the parameter in the function fwu_revert_boot_index as suggested by Etienne * Use BIT for all macros * Call the platform function fwu_plat_get_alt_num for getting the alt_num for the image partition, instead of the earlier hard-coded approach. * Change the logic in gpt_check_mdata_validity as suggested by Ilias. * Other smaller code style changes suggested by Ilias * Define a new function fwu_plat_get_alt_num using logic suggested by Patrick for returning the alt_num for the partition * Define a new function plat_fill_gpt_partition_guids to fill the guid array with Partition Type guids * Use the TAMP_BOOTCOUNT register as suggested by Yann Gautier instead of the earlier unused register 10 * Define a new function fwu_plat_get_alt_num for filling up all the dfu partitions with a preset ImageTypeId guid * Remove the distinction made in the earlier version for setting image_type_id as suggested by Heinrich * Define a funtion fwu_update_checks_pass to do the checks before initiating the update * Log the status of the boottime checks using boottime_check variable and allow system to boot instead of hanging the platform(fwu_boottime_checks) * Call function fwu_update_checks_pass to check if the update can be initiated * Do not allow firmware update from efi_init_obj_list as the fwu boot-time checks need to be run Todo's ------ 1) Add a test(selftest) for the metadata access. 2) Add a tool for generation of the metadata. Not sure if this needs to be part of the u-boot repository though. 3) Add a tool for generation of the firmware accept/reject dummy capsule. Need to check if this can be added to the mkeficapsule tool in u-boot. [1] - https://developer.arm.com/documentation/den0118/a [2] - https://staging-git.codelinaro.org/linaro/firmware-dual-banked-updates/test [3] - https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/12566 Sughosh Ganu (8): FWU: Add FWU metadata structure and functions for accessing metadata FWU: Add FWU metadata access functions 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 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 board/st/stm32mp1/stm32mp1.c | 169 ++++++++ cmd/Kconfig | 7 + cmd/Makefile | 1 + cmd/fwu_mdata.c | 64 +++ common/board_r.c | 6 + include/fwu.h | 51 +++ include/fwu_mdata.h | 104 +++++ lib/Kconfig | 32 ++ lib/Makefile | 1 + lib/efi_loader/efi_capsule.c | 198 ++++++++- lib/efi_loader/efi_firmware.c | 90 +++- lib/efi_loader/efi_setup.c | 3 +- lib/fwu_updates/Makefile | 11 + lib/fwu_updates/fwu.c | 190 +++++++++ lib/fwu_updates/fwu_mdata.c | 236 +++++++++++ lib/fwu_updates/fwu_mdata_gpt_blk.c | 635 ++++++++++++++++++++++++++++ 16 files changed, 1787 insertions(+), 11 deletions(-) create mode 100644 cmd/fwu_mdata.c create mode 100644 include/fwu.h create mode 100644 include/fwu_mdata.h create mode 100644 lib/fwu_updates/Makefile create mode 100644 lib/fwu_updates/fwu.c create mode 100644 lib/fwu_updates/fwu_mdata.c create mode 100644 lib/fwu_updates/fwu_mdata_gpt_blk.c