FWU: Add FWU Multi Bank Update feature support
Subsystems (4)
v7 cover FWU: Add FWU Multi Bank Update feature support
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
Signature · 1 line
2.34.1
PATCH v7 1/13 dt/bindings: Add bindings for FWU Metadata storage device
Add bindings needed for accessing the FWU metadata partitions. These include the compatible string which point to the access method and the actual device which stores the FWU metadata.
The current patch adds basic bindings needed for accessing the metadata structure on GPT partitioned block devices.
---
Changes since V6: None
.../firmware/fwu-mdata.yaml | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata.yaml
doc/device-tree-bindings/firmware/fwu-mdata.yaml new file +32 -0
@@ -0,0 +1,32 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/firmware/fwu-mdata.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: FWU metadata on device with GPT partitioned layout + +maintainers: + - Sughosh Ganu <[email protected]> + +properties: + compatible: + items: + - const: u-boot,fwu-mdata-gpt + + fwu-mdata-store: + maxItems: 1 + description: Phandle of the device which contains the FWU medatata partition. + +required: + - compatible + - fwu-mdata-store + +additionalProperties: false + +examples: + - | + fwu-mdata { + compatible = "u-boot,fwu-mdata-gpt"; + fwu-mdata-store = <&sdmmc1>; + };
Signature · 1 line
2.34.1
Re: [PATCH v7 01/13] dt/bindings: Add bindings for FWU Metadata storage device
Quoted 10 lines · Sughosh Ganu
Add bindings needed for accessing the FWU metadata partitions. These include the compatible string which point to the access method and the actual device which stores the FWU metadata.
The current patch adds basic bindings needed for accessing the metadata structure on GPT partitioned block devices.
Signed-off-by Sughosh Ganu <[email protected]>---
Changes since V6: None
Re: [PATCH v7 01/13] dt/bindings: Add bindings for FWU Metadata storage device
In reply to Sughosh Ganudoc/device-tree-bindings/firmware/fwu-mdata.yaml
Quoted 22 lines · Sughosh Ganu
Add bindings needed for accessing the FWU metadata partitions. These include the compatible string which point to the access method and the actual device which stores the FWU metadata.
The current patch adds basic bindings needed for accessing the metadata structure on GPT partitioned block devices.
Signed-off-by Sughosh Ganu <[email protected]>---
Changes since V6: None.../firmware/fwu-mdata.yaml | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata.yamldoc/device-tree-bindings/firmware/fwu-mdata.yaml new file +0
-0
I think we want to call it fwu-mdata-gpt.yaml ?
thanks.
Re: [PATCH v7 01/13] dt/bindings: Add bindings for FWU Metadata storage device
Quoted 18 lines · Jassi Brar
Quoted 16 lines · Sughosh Ganu
Add bindings needed for accessing the FWU metadata partitions. These include the compatible string which point to the access method and the actual device which stores the FWU metadata.
The current patch adds basic bindings needed for accessing the metadata structure on GPT partitioned block devices.
Signed-off-by Sughosh Ganu <[email protected]>---
Changes since V6: None.../firmware/fwu-mdata.yaml | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata.yaml
Quoted 7 lines
doc/device-tree-bindings/firmware/fwu-mdata.yaml
Quoted 6 lines
doc/device-tree-bindings/firmware/fwu-mdata.yaml new file +0
-0I think we want to call it
fwu-mdata-gpt.yaml?
Yes, makes sense. Will rename it. Thanks.
-sughosh
PATCH v7 2/13 FWU: Add FWU metadata structure and driver for accessing metadata
In reply to Sughosh GanuIn the FWU Multi Bank Update feature, the information about the updatable images is stored as part of the metadata, which is stored on a dedicated partition. Add the metadata structure, and a driver model uclass which provides functions to access the metadata. These are generic API's, and implementations can be added based on parameters like how the metadata partition is accessed and what type of storage device houses the metadata.
---
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 Etienne
drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fwu-mdata/Kconfig | 7 + drivers/fwu-mdata/Makefile | 6 + drivers/fwu-mdata/fwu-mdata-uclass.c | 469 +++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/fwu.h | 49 +++ include/fwu_mdata.h | 67 ++++ 8 files changed, 602 insertions(+) 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 include/fwu.h create mode 100644 include/fwu_mdata.h
drivers/Kconfig +2 -0
@@ -44,6 +44,8 @@ source "drivers/fuzz/Kconfig" source "drivers/fpga/Kconfig" +source "drivers/fwu-mdata/Kconfig" + source "drivers/gpio/Kconfig" source "drivers/hwspinlock/Kconfig"
drivers/Makefile +1 -0
@@ -83,6 +83,7 @@ obj-y += cache/ obj-$(CONFIG_CPU) += cpu/ obj-y += crypto/ obj-$(CONFIG_FASTBOOT) += fastboot/ +obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata/ obj-y += misc/ obj-$(CONFIG_MMC) += mmc/ obj-$(CONFIG_NVME) += nvme/
drivers/fwu-mdata/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config DM_FWU_MDATA + bool "Driver support for accessing FWU Metadata" + depends on DM + help + Enable support for accessing FWU Metadata partitions. The + FWU Metadata partitions reside on the same storage device + which contains the other FWU updatable firmware images.
drivers/fwu-mdata/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (c) 2022, Linaro Limited +# + +obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o
drivers/fwu-mdata/fwu-mdata-uclass.c new file +469 -0
469 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -58,6 +58,7 @@ enum uclass_id {UCLASS_FIRMWARE ,/* Firmware */ UCLASS_FUZZING_ENGINE ,/* Fuzzing engine */ UCLASS_FS_FIRMWARE_LOADER ,/* Generic loader */ +UCLASS_FWU_MDATA ,/* FWU Metadata Access */ UCLASS_GPIO ,/* Bank of general-purpose I/O pins */ UCLASS_HASH ,/* Hash device */ UCLASS_HWSPINLOCK, /* Hardware semaphores */
include/fwu.h new file +49 -0
49 lines not on this page · raw message
include/fwu_mdata.h new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v7 02/13] FWU: Add FWU metadata structure and driver for accessing metadata
Hi Sughosh,
Quoted 3 lines
+ */
drivers/fwu-mdata/fwu-mdata-uclass.c new file +2
-0+ +#define LOG_CATEGORY UCLASS_FWU_MDATA
[...]
Quoted 11 lines
drivers/fwu-mdata/fwu-mdata-uclass.c new file +10
-0+ +/** +* fwu_verify_mdata() - Verify the FWU metadata +* @mdata: FWU metadata structure +* @pri_part: FWU metadata partition is primary or secondary +* +* Verify the FWU metadata by computing the CRC32 for the metadata +* structure and comparing it against the CRC32 value stored as part +* of the structure. +/**
drivers/fwu-mdata/fwu-mdata-uclass.c line 123
Quoted 10 lines
drivers/fwu-mdata/fwu-mdata-uclass.c new file +9
-0+* fwu_update_active_index() - Update active_index from the FWU metadata +* @active_idx: active_index value to be updated +int fwu_update_active_index(u32 active_idx) +{ +int ret; +struct fwu_mdata *mdata = NULL; + +if (active_idx > CONFIG_FWU_NUM_BANKS - 1) { +log_err("Active index value to be updated is incorrect\n");
Nit but "Invalid active index value" is makes more sense
Quoted 3 lines
drivers/fwu-mdata/fwu-mdata-uclass.c new file +3
-0+return -1 ; + } +
[...]
Quoted 41 lines
drivers/fwu-mdata/fwu-mdata-uclass.c new file +41
-0+} + +/** +* fwu_get_image_alt_num() - Get the dfu alt number to be used for capsule update +* @image_type_id: pointer to the image guid as passed in the capsule +* @update_bank: Bank to which the update is to be made +* @alt_num: The alt_num for the image +* +* Based on the guid value passed in the capsule, along with the bank to which the +* image needs to be updated, get the dfu alt number which will be used for the +* capsule update +* +* Return: 0 if OK, -ve on error +* +*/ +int fwu_get_image_alt_num (efi_guid_t *image_type_id,u32 update_bank, +int *alt_num) +{ +int ret, i; +efi_guid_t *image_guid; +struct udevice *dev =NULL ; +struct fwu_mdata *mdata =NULL ; +struct fwu_image_entry *img_entry; +const struct fwu_mdata_ops *ops =NULL ; +struct fwu_image_bank_info *img_bank_info; + + ret =fwu_get_dev_ops (&dev, &ops); +if (ret) +return ret; + + ret =fwu_get_mdata (&mdata); +if (ret) { +log_err ("Unable to get valid FWU metadata\n" ); + goto out; + } + +/* +* The FWU metadata has been read. Now get the image_uuid for the +* image with the update_bank. +*/ +for (i =0 ; i <CONFIG_FWU_NUM_IMAGES_PER_BANK ; i++) {
drivers/fwu-mdata/fwu-mdata-uclass.c line 204
Quoted 10 lines
drivers/fwu-mdata/fwu-mdata-uclass.c new file +10
-0+if (!guidcmp (image_type_id, + &mdata->img_entry[i].image_type_uuid)) { + img_entry = &mdata->img_entry[i]; + img_bank_info = &img_entry->img_bank_info[update_bank]; + image_guid = &img_bank_info->image_uuid; + ret =fwu_plat_get_alt_num (dev, image_guid, alt_num); +break ; + } + } +
I think if you set ret = -EINVAL on top of the for loop you can mostly get rid of the code below.
ret = -EINVAL
for () {
.....
ret = fwu_plat_get_alt_num(dev, image_guid, alt_num);
if (ret)
log_err("alt_num not found for partition with GUID %pUs\n", image_guid);
goto out; //on success instead of break
}log_err("Partition with the image type %pUs not found\n", image_type_id);
out:
free(mdata);
return ret;
Isn't that more readable?
Quoted 13 lines
drivers/fwu-mdata/fwu-mdata-uclass.c new file +13
-0+if (i ==CONFIG_FWU_NUM_IMAGES_PER_BANK ) { +log_err ("Partition with the image type %pUs not found\n" , + image_type_id); + ret = -EINVAL ; + goto out; + } + +if (!ret) { +log_debug ("alt_num %d for partition %pUs\n" , + *alt_num, image_guid); + }else { +log_err ("alt_num not found for partition with GUID %pUs\n" , + image_guid);
drivers/fwu-mdata/fwu-mdata-uclass.c line 227
Quoted 10 lines
drivers/fwu-mdata/fwu-mdata-uclass.c new file +10
-0+ ret = -EINVAL ; + } + +out: +free (mdata); + +return ret; +} + +/**
[...]
u32 bank, u8 action)
drivers/fwu-mdata/fwu-mdata-uclass.c line 319
Quoted 3 lines
drivers/fwu-mdata/fwu-mdata-uclass.c new file +3
-0+{ +int ret, i; +u32 nimages;
Get rid of nimages when they are only used as CONFIG_FWU_NUM_IMAGES_PER_BANK (there's more than one)
[...]
Quoted 18 lines
include/dm/uclass-id.h +15
-0@@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (c) 2022, Linaro Limited +*/ + +#if !defined _FWU_MDATA_H_ +#define _FWU_MDATA_H_ + +#include <efi.h> + +/** +* struct fwu_image_bank_info - firmware image information +* @image_uuid: Guid value of the image in this bank +* @accepted: Acceptance status of the image +* @reserved: Reserved
include/dm/uclass-id.h line 25
Quoted 10 lines
include/dm/uclass-id.h +10
-0+* +* The structure contains image specific fields which are +* used to identify the image and to specify the image's +* acceptance status +*/ +struct fwu_image_bank_info { +efi_guid_t image_uuid; +uint32_t accepted; +uint32_t reserved; +} __attribute__((__packed__ ));
The spec doesn't require those to be packed. If there's a reason we should have it in comments, otherwise just drop the packed attribute
Quoted 43 lines
include/dm/uclass-id.h +42
-1+ +/** +* struct fwu_image_entry - information for a particular type of image +* @image_type_uuid: Guid value for identifying the image type +* @location_uuid: Guid of the storage volume where the image is located +* @img_bank_info: Array containing properties of images +* +* This structure contains information on various types of updatable +* firmware images. Each image type then contains an array of image +* information per bank. +*/ +struct fwu_image_entry { +efi_guid_t image_type_uuid; +efi_guid_t location_uuid; +struct fwu_image_bank_info img_bank_info[CONFIG_FWU_NUM_BANKS ]; +} __attribute__((__packed__ )); + +/** +* struct fwu_mdata - FWU metadata structure for multi-bank updates +* @crc32: crc32 value for the FWU metadata +* @version: FWU metadata version +* @active_index: Index of the bank currently used for booting images +* @previous_active_inde: Index of the bank used before the current bank +* being used for booting +* @img_entry: Array of information on various firmware images that can +* be updated +* +* This structure is used to store all the needed information for performing +* multi bank updates on the platform. This contains info on the bank being +* used to boot along with the information needed for identification of +* individual images +*/ +struct fwu_mdata { +uint32_t crc32; +uint32_t version; +uint32_t active_index; +uint32_t previous_active_index; + +struct fwu_image_entry img_entry[CONFIG_FWU_NUM_IMAGES_PER_BANK ]; +} __attribute__((__packed__ )); + +#endif /* _FWU_MDATA_H_ */ --
Quoted 2 lines
2.34.1
Thanks!
/Ilias
PATCH v7 3/13 FWU: Add FWU metadata access driver for GPT partitioned block devices
In reply to Sughosh GanuIn the FWU Multi Bank Update feature, the information about the updatable images is stored as part of the metadata, on a separate partition. Add a driver for reading from and writing to the metadata when the updatable images and the metadata are stored on a block device which is formated with GPT based partition scheme.
---
Changes since V6:
* Define the LOG_CATEGORY macro as suggested by Patrick
drivers/fwu-mdata/Kconfig | 9 + drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/fwu_mdata_gpt_blk.c | 410 ++++++++++++++++++++++++++ include/fwu.h | 5 + 4 files changed, 425 insertions(+) create mode 100644 drivers/fwu-mdata/fwu_mdata_gpt_blk.c
drivers/fwu-mdata/Kconfig +9 -0
@@ -5,3 +5,12 @@ config DM_FWU_MDATA Enable support for accessing FWU Metadata partitions. The FWU Metadata partitions reside on the same storage device which contains the other FWU updatable firmware images. + +config FWU_MDATA_GPT_BLK + bool "FWU Metadata access for GPT partitioned Block devices" + select PARTITION_TYPE_GUID + select PARTITION_UUIDS + depends on DM && HAVE_BLOCK_DEVICE && EFI_PARTITION + help + Enable support for accessing FWU Metadata on GPT partitioned + block devices.
drivers/fwu-mdata/Makefile +1 -0
@@ -4,3 +4,4 @@ # obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o +obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata_gpt_blk.o
drivers/fwu-mdata/fwu_mdata_gpt_blk.c new file +410 -0
410 lines not on this page · raw message
include/fwu.h +5 -0
@@ -14,6 +14,10 @@struct fwu_mdata ;struct udevice ; +struct fwu_mdata_gpt_blk_priv { +struct udevice *blk_dev; +}; +/** * @mdata_check: check the validity of the FWU metadata partitions * @get_mdata() - Get a FWU metadata copy
@@ -39,6 +43,7 @@ int fwu_get_active_index(u32 *active_idx);int fwu_update_active_index (u32 active_idx);int fwu_get_image_alt_num (efi_guid_t *image_type_id,u32 update_bank,int *alt_num); +int fwu_verify_mdata (struct fwu_mdata *mdata,bool pri_part);int fwu_mdata_check (void );int fwu_revert_boot_index (void );int fwu_accept_image (efi_guid_t *img_type_id,u32 bank);
Signature · 1 line
2.34.1
PATCH v7 4/13 stm32mp1: dk2: Add a node for the FWU metadata device
In reply to Sughosh GanuThe FWU metadata structure is accessed through the driver model interface. On the stm32mp157c-dk2 board, the FWU metadata is stored on the uSD card. Add the fwu-mdata node on the u-boot specifc dtsi file for accessing the metadata structure.
---
Changes since V6: None
arch/arm/dts/stm32mp157c-dk2-u-boot.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm/dts/stm32mp157c-dk2-u-boot.dtsi +7 -0
@@ -4,3 +4,10 @@ */ #include "stm32mp157a-dk1-u-boot.dtsi" + +/ { + fwu-mdata { + compatible = "u-boot,fwu-mdata-gpt"; + fwu-mdata-store = <&sdmmc1>; + }; +};
Signature · 1 line
2.34.1
Re: [PATCH v7 04/13] stm32mp1: dk2: Add a node for the FWU metadata device
Quoted 30 lines · Sughosh Ganu
The FWU metadata structure is accessed through the driver model interface. On the stm32mp157c-dk2 board, the FWU metadata is stored on the uSD card. Add the fwu-mdata node on the u-boot specifc dtsi file for accessing the metadata structure.
Signed-off-by Sughosh Ganu <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>---
Changes since V6: Nonearch/arm/dts/stm32mp157c-dk2-u-boot.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)arch/arm/dts/stm32mp157c-dk2-u-boot.dtsi +7
-1@@ -4,3 +4,10 @@ */ #include "stm32mp157a-dk1-u-boot.dtsi" + +/ { + fwu-mdata { + compatible = "u-boot,fwu-mdata-gpt"; + fwu-mdata-store = <&sdmmc1>; + }; +}; --
Quoted 2 lines
2.34.1
PATCH v7 5/13 stm32mp1: dk2: Add image information for capsule updates
In reply to Sughosh GanuEnabling capsule update functionality on the platform requires populating information on the images that are to be updated using the functionality. Do so for the DK2 board.
---
Changes since V6:
* s/STM32MP1/STM32MP15/ as suggested by Patrick
board/st/stm32mp1/stm32mp1.c | 19 +++++++++++++++++++ include/configs/stm32mp15_common.h | 4 ++++ 2 files changed, 23 insertions(+)
board/st/stm32mp1/stm32mp1.c +19 -0
@@ -11,6 +11,7 @@#include <clk.h> #include <config.h> #include <dm.h> +#include <efi_loader.h> #include <env.h> #include <env_internal.h> #include <fdt_simplefb.h>
@@ -87,6 +88,16 @@#define USB_START_LOW_THRESHOLD_UV 1230000#define USB_START_HIGH_THRESHOLD_UV 2150000 +#if CONFIG_IS_ENABLED (EFI_HAVE_CAPSULE_SUPPORT ) +struct efi_fw_image fw_images[1 ]; + +struct efi_capsule_update_info update_info = { + .images = fw_images, +}; + +u8 num_image_type_guids =ARRAY_SIZE (fw_images); +#endif /* EFI_HAVE_CAPSULE_SUPPORT */ +int board_early_init_f (void ) {/* nothing to do, only used in SPL */
@@ -670,6 +681,14 @@ int board_init(void)setup_led (LEDST_ON ); +#if CONFIG_IS_ENABLED (EFI_HAVE_CAPSULE_SUPPORT ) +if (board_is_stm32mp15x_dk2 ()) { +efi_guid_t image_type_guid =STM32MP15_DK2_FIP_IMAGE_GUID ; +guidcpy (&fw_images[0 ].image_type_id, &image_type_guid); + fw_images[0 ].fw_name =u"STM32MP15-DK2-FIP" ; + fw_images[0 ].image_index =5 ; + } +#endif return 0 ; }
include/configs/stm32mp15_common.h +4 -0
@@ -34,6 +34,10 @@#define CONFIG_SERVERIP 192.168.1.1#endif +#define STM32MP15_DK2_FIP_IMAGE_GUID \ + EFI_GUID(0x19d5df83, 0x11b0, 0x457b, 0xbe, 0x2c, \ + 0x75, 0x59, 0xc1, 0x31, 0x42, 0xa5) +/*****************************************************************************/ #ifdef CONFIG_DISTRO_DEFAULTS /*****************************************************************************/
Signature · 1 line
2.34.1
Re: [PATCH v7 05/13] stm32mp1: dk2: Add image information for capsule updates
Quoted 75 lines · Sughosh Ganu
Enabling capsule update functionality on the platform requires populating information on the images that are to be updated using the functionality. Do so for the DK2 board.
Signed-off-by Sughosh Ganu <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>---
Changes since V6:
* s/STM32MP1/STM32MP15/ as suggested by Patrickboard/st/stm32mp1/stm32mp1.c | 19 +++++++++++++++++++ include/configs/stm32mp15_common.h | 4 ++++ 2 files changed, 23 insertions(+)board/st/stm32mp1/stm32mp1.c +19
-0@@ -11,6 +11,7 @@#include <clk.h> #include <config.h> #include <dm.h> +#include <efi_loader.h> #include <env.h> #include <env_internal.h> #include <fdt_simplefb.h> @@ -87,6 +88,16 @@#define USB_START_LOW_THRESHOLD_UV 1230000#define USB_START_HIGH_THRESHOLD_UV 2150000 +#if CONFIG_IS_ENABLED (EFI_HAVE_CAPSULE_SUPPORT ) +struct efi_fw_image fw_images[1 ]; + +struct efi_capsule_update_info update_info = { + .images = fw_images, +}; + +u8 num_image_type_guids =ARRAY_SIZE (fw_images); +#endif /* EFI_HAVE_CAPSULE_SUPPORT */ +int board_early_init_f (void ) {/* nothing to do, only used in SPL */ @@ -670,6 +681,14 @@ int board_init(void)setup_led (LEDST_ON ); +#if CONFIG_IS_ENABLED (EFI_HAVE_CAPSULE_SUPPORT ) +if (board_is_stm32mp15x_dk2 ()) { +efi_guid_t image_type_guid =STM32MP15_DK2_FIP_IMAGE_GUID ; +guidcpy (&fw_images[0 ].image_type_id, &image_type_guid); + fw_images[0 ].fw_name =u"STM32MP15-DK2-FIP" ; + fw_images[0 ].image_index =5 ; + } +#endif return 0 ; }include/configs/stm32mp15_common.h +4
-1@@ -34,6 +34,10 @@#define CONFIG_SERVERIP 192.168.1.1#endif +#define STM32MP15_DK2_FIP_IMAGE_GUID \ + EFI_GUID(0x19d5df83, 0x11b0, 0x457b, 0xbe, 0x2c, \ + 0x75, 0x59, 0xc1, 0x31, 0x42, 0xa5) +/*****************************************************************************/ #ifdef CONFIG_DISTRO_DEFAULTS /*****************************************************************************/ --
Quoted 2 lines
2.34.1
PATCH v7 6/13 FWU: stm32mp1: Add helper functions for accessing FWU metadata
In reply to Sughosh GanuAdd helper functions needed for accessing the FWU metadata which contains information on the updatable images. These functions have been added for the STM32MP157C-DK2 board which has the updatable images on the uSD card, formatted as GPT partitions.
---
Changes since V6: None
board/st/stm32mp1/stm32mp1.c | 40 ++++++++++++++++ include/fwu.h | 3 ++ lib/fwu_updates/Makefile | 6 +++ lib/fwu_updates/fwu_gpt.c | 88 ++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 lib/fwu_updates/Makefile create mode 100644 lib/fwu_updates/fwu_gpt.c
board/st/stm32mp1/stm32mp1.c +40 -0
@@ -7,9 +7,11 @@#include <common.h> #include <adc.h> +#include <blk.h> #include <bootm.h> #include <clk.h> #include <config.h> +#include <dfu.h> #include <dm.h> #include <efi_loader.h> #include <env.h>
@@ -25,9 +27,11 @@#include <log.h> #include <malloc.h> #include <misc.h> +#include <mmc.h> #include <mtd_node.h> #include <net.h> #include <netdev.h> +#include <part.h> #include <phy.h> #include <remoteproc.h> #include <reset.h>
@@ -962,3 +966,39 @@ static void board_copro_image_process(ulong fw_image, size_t fw_size) }U_BOOT_FIT_LOADABLE_HANDLER (IH_TYPE_COPRO , board_copro_image_process); + +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE ) + +#include <fwu.h> +#include <fwu_mdata.h> + +int fwu_plat_get_alt_num (struct udevice *dev,efi_guid_t *image_guid, +int *alt_num) +{ +struct blk_desc *desc; +struct fwu_mdata_gpt_blk_priv *priv =dev_get_priv (dev); + + desc =dev_get_uclass_plat (priv->blk_dev); +if (!desc) { +log_err ("Block device not found\n" ); +return -ENODEV ; + } + +return fwu_gpt_get_alt_num (desc, image_guid, alt_num,DFU_DEV_MMC ); +} + +int fwu_plat_get_update_index (u32 *update_idx) +{ +int ret; +u32 active_idx; + + ret =fwu_get_active_index (&active_idx); + +if (ret <0 ) +return -1 ; + + *update_idx = active_idx ^=0x1 ; + +return ret; +} +#endif /* CONFIG_FWU_MULTI_BANK_UPDATE */
include/fwu.h +3 -0
@@ -51,4 +51,7 @@ int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank);int fwu_plat_get_alt_num (struct udevice *dev,efi_guid_t *image_guid,int *alt_num); +int fwu_gpt_get_alt_num (struct blk_desc *desc,efi_guid_t *image_guid, +int *alt_num,unsigned char dfu_dev); +int fwu_plat_get_update_index (u32 *update_idx);#endif /* _FWU_H_ */
lib/fwu_updates/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c) 2022, Linaro Limited +# + +obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_gpt.o
lib/fwu_updates/fwu_gpt.c new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v7 06/13] FWU: stm32mp1: Add helper functions for accessing FWU metadata
Hi Sughosh,
Quoted 76 lines · Sughosh Ganu
Add helper functions needed for accessing the FWU metadata which contains information on the updatable images. These functions have been added for the STM32MP157C-DK2 board which has the updatable images on the uSD card, formatted as GPT partitions.
Signed-off-by Sughosh Ganu <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>---
Changes since V6: Noneboard/st/stm32mp1/stm32mp1.c | 40 ++++++++++++++++ include/fwu.h | 3 ++ lib/fwu_updates/Makefile | 6 +++ lib/fwu_updates/fwu_gpt.c | 88 ++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 lib/fwu_updates/Makefile create mode 100644 lib/fwu_updates/fwu_gpt.cboard/st/stm32mp1/stm32mp1.c +29
-0@@ -7,9 +7,11 @@#include <common.h> #include <adc.h> +#include <blk.h> #include <bootm.h> #include <clk.h> #include <config.h> +#include <dfu.h> #include <dm.h> #include <efi_loader.h> #include <env.h> @@ -25,9 +27,11 @@#include <log.h> #include <malloc.h> #include <misc.h> +#include <mmc.h> #include <mtd_node.h> #include <net.h> #include <netdev.h> +#include <part.h> #include <phy.h> #include <remoteproc.h> #include <reset.h> @@ -962,3 +966,39 @@ static void board_copro_image_process(ulong fw_image, size_t fw_size) }U_BOOT_FIT_LOADABLE_HANDLER (IH_TYPE_COPRO , board_copro_image_process); + +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE ) + +#include <fwu.h> +#include <fwu_mdata.h> + +int fwu_plat_get_alt_num (struct udevice *dev,efi_guid_t *image_guid, +int *alt_num) +{ +struct blk_desc *desc; +struct fwu_mdata_gpt_blk_priv *priv =dev_get_priv (dev); + + desc =dev_get_uclass_plat (priv->blk_dev); +if (!desc) { +log_err ("Block device not found\n" ); +return -ENODEV ; + } + +return fwu_gpt_get_alt_num (desc, image_guid, alt_num,DFU_DEV_MMC ); +} + +int fwu_plat_get_update_index (u32 *update_idx) +{ +int ret; +u32 active_idx;
board/st/stm32mp1/stm32mp1.c static void board_copro_image_process(ulong fw_image, size_t fw_size) · line 1003
Quoted 10 lines
board/st/stm32mp1/stm32mp1.c +10
-0+ + ret =fwu_get_active_index (&active_idx); + +if (ret <0 ) +return -1 ; + + *update_idx = active_idx ^=0x1 ; + +return ret; +}
I'dl ike to move those 2 out to the generic API as well. Sure a device might be paranoid and have more than 2 banks for firmware redundancy, however I believe 2 will be the main case. So we can use these 2 as generic weak functions and special devices can override that
Regards
/Ilias
Quoted 5 lines
board/st/stm32mp1/stm32mp1.c +1
-0+#endif /* CONFIG_FWU_MULTI_BANK_UPDATE */ include/fwu.h +0
-0
[...]
Re: [PATCH v7 06/13] FWU: stm32mp1: Add helper functions for accessing FWU metadata
In reply to Sughosh GanuQuoted 11 lines · Sughosh Ganu
Add helper functions needed for accessing the FWU metadata which contains information on the updatable images. These functions have been added for the STM32MP157C-DK2 board which has the updatable images on the uSD card, formatted as GPT partitions.
Signed-off-by Sughosh Ganu <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>---
Changes since V6: None
Quoted 8 lines
board/st/stm32mp1/stm32mp1.c | 40 ++++++++++++++++ include/fwu.h | 3 ++ lib/fwu_updates/Makefile | 6 +++ lib/fwu_updates/fwu_gpt.c | 88 ++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 lib/fwu_updates/Makefile create mode 100644 lib/fwu_updates/fwu_gpt.c
fwu_gpt is to be used by all platforms that have the gpt-scheme, not just STM.
So do you want to break this patch into two ? One generic that introduces the helper functions and another for stm using that api
Also, you may want to specify GPL-2.0-or-later everywhere.
thanks.
Re: [PATCH v7 06/13] FWU: stm32mp1: Add helper functions for accessing FWU metadata
Quoted 21 lines · Jassi Brar
Quoted 11 lines · Sughosh Ganu
Add helper functions needed for accessing the FWU metadata which contains information on the updatable images. These functions have been added for the STM32MP157C-DK2 board which has the updatable images on the uSD card, formatted as GPT partitions.
Signed-off-by Sughosh Ganu <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>---
Changes since V6: NoneQuoted 8 lines
board/st/stm32mp1/stm32mp1.c | 40 ++++++++++++++++ include/fwu.h | 3 ++ lib/fwu_updates/Makefile | 6 +++ lib/fwu_updates/fwu_gpt.c | 88 ++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 lib/fwu_updates/Makefile create mode 100644 lib/fwu_updates/fwu_gpt.c
Quoted 4 lines
fwu_gptis to be used by all platforms that have the gpt-scheme, not just STM.So do you want to break this patch into two ? One generic that introduces the helper functions and another for stm using that api
Ilias has suggested moving the two API functions to common files and having them defined as weak functions. I will be making this change in the next version.
Quoted 2 lines
Also, you may want to specify GPL-2.0-or-later everywhere.
I thought I had changed that in this version of the patchset, but unfortunately these two files have not been changed. I will change this in the next version.
-sughosh
PATCH v7 7/13 FWU: STM32MP1: Add support to read boot index from backup register
In reply to Sughosh GanuThe FWU Multi Bank Update feature allows the platform to boot the firmware images from one of the partitions(banks). The first stage bootloader(fsbl) passes the value of the boot index, i.e. the bank from which the firmware images were booted from to U-Boot. On the STM32MP157C-DK2 board, this value is passed through one of the SoC's backup register. Add a function to read the boot index value from the backup register.
---
Changes since V6: None
arch/arm/mach-stm32mp/include/mach/stm32.h | 5 +++++ board/st/stm32mp1/stm32mp1.c | 8 ++++++++ include/fwu.h | 1 + 3 files changed, 14 insertions(+)
arch/arm/mach-stm32mp/include/mach/stm32.h +5 -0
@@ -112,11 +112,16 @@ enum boot_device {#ifdef CONFIG_STM32MP15x#define TAMP_BACKUP_MAGIC_NUMBER TAMP_BACKUP_REGISTER(4)#define TAMP_BACKUP_BRANCH_ADDRESS TAMP_BACKUP_REGISTER(5) +#define TAMP_FWU_BOOT_INFO_REG TAMP_BACKUP_REGISTER(10)#define TAMP_COPRO_RSC_TBL_ADDRESS TAMP_BACKUP_REGISTER(17)#define TAMP_COPRO_STATE TAMP_BACKUP_REGISTER(18)#define TAMP_BOOT_CONTEXT TAMP_BACKUP_REGISTER(20)#define TAMP_BOOTCOUNT TAMP_BACKUP_REGISTER(21) +#define TAMP_FWU_BOOT_IDX_MASK GENMASK(3, 0) + +#define TAMP_FWU_BOOT_IDX_OFFSET 0 +#define TAMP_COPRO_STATE_OFF 0#define TAMP_COPRO_STATE_INIT 1#define TAMP_COPRO_STATE_CRUN 2
board/st/stm32mp1/stm32mp1.c +8 -0
@@ -1001,4 +1001,12 @@ int fwu_plat_get_update_index(u32 *update_idx) return ret; } + +void fwu_plat_get_bootidx (void *boot_idx) +{ +u32 *bootidx = boot_idx; + + *bootidx = (readl (TAMP_FWU_BOOT_INFO_REG ) >> +TAMP_FWU_BOOT_IDX_OFFSET ) &TAMP_FWU_BOOT_IDX_MASK ; +}#endif /* CONFIG_FWU_MULTI_BANK_UPDATE */
include/fwu.h +1 -0
@@ -49,6 +49,7 @@ int fwu_revert_boot_index(void);int fwu_accept_image (efi_guid_t *img_type_id,u32 bank);int fwu_clear_accept_image (efi_guid_t *img_type_id,u32 bank); +void fwu_plat_get_bootidx (void *boot_idx);int fwu_plat_get_alt_num (struct udevice *dev,efi_guid_t *image_guid,int *alt_num); int fwu_gpt_get_alt_num(struct blk_desc *desc, efi_guid_t *image_guid,
Signature · 1 line
2.34.1
Re: [PATCH v7 07/13] FWU: STM32MP1: Add support to read boot index from backup register
Quoted 70 lines · Sughosh Ganu
The FWU Multi Bank Update feature allows the platform to boot the firmware images from one of the partitions(banks). The first stage bootloader(fsbl) passes the value of the boot index, i.e. the bank from which the firmware images were booted from to U-Boot. On the STM32MP157C-DK2 board, this value is passed through one of the SoC's backup register. Add a function to read the boot index value from the backup register.
Signed-off-by Sughosh Ganu <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>---
Changes since V6: Nonearch/arm/mach-stm32mp/include/mach/stm32.h | 5 +++++ board/st/stm32mp1/stm32mp1.c | 8 ++++++++ include/fwu.h | 1 + 3 files changed, 14 insertions(+)arch/arm/mach-stm32mp/include/mach/stm32.h +5
-0@@ -112,11 +112,16 @@ enum boot_device {#ifdef CONFIG_STM32MP15x#define TAMP_BACKUP_MAGIC_NUMBER TAMP_BACKUP_REGISTER(4)#define TAMP_BACKUP_BRANCH_ADDRESS TAMP_BACKUP_REGISTER(5) +#define TAMP_FWU_BOOT_INFO_REG TAMP_BACKUP_REGISTER(10)#define TAMP_COPRO_RSC_TBL_ADDRESS TAMP_BACKUP_REGISTER(17)#define TAMP_COPRO_STATE TAMP_BACKUP_REGISTER(18)#define TAMP_BOOT_CONTEXT TAMP_BACKUP_REGISTER(20)#define TAMP_BOOTCOUNT TAMP_BACKUP_REGISTER(21) +#define TAMP_FWU_BOOT_IDX_MASK GENMASK(3, 0) + +#define TAMP_FWU_BOOT_IDX_OFFSET 0 +#define TAMP_COPRO_STATE_OFF 0#define TAMP_COPRO_STATE_INIT 1#define TAMP_COPRO_STATE_CRUN 2board/st/stm32mp1/stm32mp1.c +8
-0@@ -1001,4 +1001,12 @@ int fwu_plat_get_update_index(u32 *update_idx) return ret; } + +void fwu_plat_get_bootidx (void *boot_idx) +{ +u32 *bootidx = boot_idx; + + *bootidx = (readl (TAMP_FWU_BOOT_INFO_REG ) >> +TAMP_FWU_BOOT_IDX_OFFSET ) &TAMP_FWU_BOOT_IDX_MASK ; +}#endif /* CONFIG_FWU_MULTI_BANK_UPDATE */ include/fwu.h +1
-1@@ -49,6 +49,7 @@ int fwu_revert_boot_index(void);int fwu_accept_image (efi_guid_t *img_type_id,u32 bank);int fwu_clear_accept_image (efi_guid_t *img_type_id,u32 bank); +void fwu_plat_get_bootidx (void *boot_idx);int fwu_plat_get_alt_num (struct udevice *dev,efi_guid_t *image_guid,int *alt_num); int fwu_gpt_get_alt_num(struct blk_desc *desc, efi_guid_t *image_guid, --
Quoted 2 lines
2.34.1
PATCH v7 8/13 FWU: Add boot time checks as highlighted by the FWU specification
In reply to Sughosh GanuThe FWU Multi Bank Update specification requires the Update Agent to carry out certain checks at the time of platform boot. The Update Agent is the component which is responsible for updating the firmware components and maintaining and keeping the metadata in sync.
The spec requires that the Update Agent perform the following checks at the time of boot
* Sanity check of both the metadata copies maintained by the platform.
* Get the boot index passed to U-Boot by the prior stage bootloader and use this value for metadata bookkeeping.
* Check if the system is booting in Trial State. If the system boots in the Trial State for more than a specified number of boot counts, change the Active Bank to be booting the platform from.
Add these checks in the board initialisation sequence, invoked after relocation.
---
Changes since V6: None
common/board_r.c | 5 ++ include/fwu.h | 3 + lib/fwu_updates/fwu.c | 165 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 lib/fwu_updates/fwu.c
common/board_r.c +5 -0
@@ -15,6 +15,7 @@#include <cpu_func.h> #include <exports.h> #include <flash.h> +#include <fwu.h> #include <hang.h> #include <image.h> #include <irq_func.h>
@@ -785,6 +786,10 @@ static init_fnc_t init_sequence_r[] = {#if defined(CONFIG_PRAM ) initr_mem,#endif + +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE + fwu_boottime_checks, +#endif run_main_loop, };
include/fwu.h +3 -0
@@ -37,6 +37,9 @@ struct fwu_mdata_ops {EFI_GUID (0x8a7a84a0 ,0x8387 ,0x40f6 ,0xab ,0x41 , \ 0xa8, 0xb9, 0xa5, 0xa6, 0x0d, 0x23) +u8 fwu_update_checks_pass (void ); +int fwu_boottime_checks (void ); +int fwu_get_mdata (struct fwu_mdata **mdata);int fwu_update_mdata (struct fwu_mdata *mdata);int fwu_get_active_index (u32 *active_idx);
lib/fwu_updates/fwu.c new file +165 -0
165 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v7 08/13] FWU: Add boot time checks as highlighted by the FWU specification
Hi Sughosh,
Quoted 96 lines · Sughosh Ganu
The FWU Multi Bank Update specification requires the Update Agent to carry out certain checks at the time of platform boot. The Update Agent is the component which is responsible for updating the firmware components and maintaining and keeping the metadata in sync.
The spec requires that the Update Agent perform the following checks at the time of boot
* Sanity check of both the metadata copies maintained by the platform.
* Get the boot index passed to U-Boot by the prior stage bootloader and use this value for metadata bookkeeping.
* Check if the system is booting in Trial State. If the system boots in the Trial State for more than a specified number of boot counts, change the Active Bank to be booting the platform from.Add these checks in the board initialisation sequence, invoked after relocation.
Signed-off-by Sughosh Ganu <[email protected]>---
Changes since V6: Nonecommon/board_r.c | 5 ++ include/fwu.h | 3 + lib/fwu_updates/fwu.c | 165 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 lib/fwu_updates/fwu.ccommon/board_r.c +5
-0@@ -15,6 +15,7 @@#include <cpu_func.h> #include <exports.h> #include <flash.h> +#include <fwu.h> #include <hang.h> #include <image.h> #include <irq_func.h> @@ -785,6 +786,10 @@ static init_fnc_t init_sequence_r[] = {#if defined(CONFIG_PRAM ) initr_mem,#endif + +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE + fwu_boottime_checks, +#endif run_main_loop, };include/fwu.h +3
-0@@ -37,6 +37,9 @@ struct fwu_mdata_ops {EFI_GUID (0x8a7a84a0 ,0x8387 ,0x40f6 ,0xab ,0x41 , \ 0xa8, 0xb9, 0xa5, 0xa6, 0x0d, 0x23) +u8 fwu_update_checks_pass (void ); +int fwu_boottime_checks (void ); +int fwu_get_mdata (struct fwu_mdata **mdata);int fwu_update_mdata (struct fwu_mdata *mdata);int fwu_get_active_index (u32 *active_idx);lib/fwu_updates/fwu.c new file +25
-0@@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022, Linaro Limited +*/ + +#include <dm.h> +#include <efi.h> +#include <efi_loader.h> +#include <efi_variable.h> +#include <fwu.h> +#include <fwu_mdata.h> +#include <malloc.h> + +#include <linux/errno.h> +#include <linux/types.h> + +static u8 trial_state; +static u8 boottime_check; + +static int fwu_trial_state_check (void ) +{ +int ret, i; +efi_status_t status; +efi_uintn_t var_size; +u16 trial_state_ctr;
lib/fwu_updates/fwu.c line 35
Quoted 10 lines
lib/fwu_updates/fwu.c new file +10
-0+u32 nimages, active_bank, var_attributes, active_idx; +struct fwu_mdata *mdata =NULL ; +struct fwu_image_entry *img_entry; +struct fwu_image_bank_info *img_bank_info; + + ret =fwu_get_mdata (&mdata); +if (ret) +return ret; + + ret =0 ;
Is ret = 0 needed here? Isn't it 0 already ?
lib/fwu_updates/fwu.c line 45
Quoted 10 lines
lib/fwu_updates/fwu.c new file +10
-0+ nimages =CONFIG_FWU_NUM_IMAGES_PER_BANK ; + active_bank = mdata->active_index; + img_entry = &mdata->img_entry[0 ]; +for (i =0 ; i < nimages; i++) { + img_bank_info = &img_entry[i].img_bank_info[active_bank]; +if (!img_bank_info->accepted) { + trial_state =1 ; +break ; + } + }
Is this used elsewhere in the patchset? The function is starting to be big, so perhaps moving this in a static bool "in_trial_state()" or similar would make it more readable.
Quoted 44 lines
lib/fwu_updates/fwu.c new file +44
-0+ +if (trial_state) { + var_size = (efi_uintn_t )sizeof (trial_state_ctr); +log_info ("System booting in Trial State\n" ); + var_attributes =EFI_VARIABLE_NON_VOLATILE | +EFI_VARIABLE_BOOTSERVICE_ACCESS ; + status =efi_get_variable_int (u"TrialStateCtr" , + &efi_global_variable_guid, + &var_attributes, + &var_size, &trial_state_ctr, +NULL ); +if (status !=EFI_SUCCESS ) { +log_err ("Unable to read TrialStateCtr variable\n" ); + ret =-1 ; + goto out; + } + + ++trial_state_ctr; +if (trial_state_ctr >CONFIG_FWU_TRIAL_STATE_CNT ) { +log_info ("Trial State count exceeded. Revert back to previous_active_index\n" ); + active_idx = mdata->active_index; + ret =fwu_revert_boot_index (); +if (ret) { +log_err ("Unable to revert active_index\n" ); + goto out; + } + +/* Delete the TrialStateCtr variable */ + status =efi_set_variable_int (u"TrialStateCtr" , + &efi_global_variable_guid, + var_attributes, +0 ,NULL , false); +if (status !=EFI_SUCCESS ) { +log_err ("Unable to delete TrialStateCtr variable\n" ); + ret =-1 ; + goto out; + } + }else { + status =efi_set_variable_int (u"TrialStateCtr" , + &efi_global_variable_guid, + var_attributes, + var_size, + &trial_state_ctr, false); +if (status !=EFI_SUCCESS ) {
lib/fwu_updates/fwu.c line 99
Quoted 10 lines
lib/fwu_updates/fwu.c new file +10
-0+log_err ("Unable to increment TrialStateCtr variable\n" ); + ret =-1 ; + goto out; + } + } + }else { +/* Delete the variable */ + status =efi_set_variable_int (u"TrialStateCtr" , + &efi_global_variable_guid, +0 ,0 ,NULL ,NULL );
the last argument should be false
lib/fwu_updates/fwu.c line 100
Quoted 1 line
lib/fwu_updates/fwu.c new file +1
-0+if (status !=EFI_SUCCESS && status !=EFI_NOT_FOUND ) {
Is there a chance the code will try to delete the variable when it's not there?
lib/fwu_updates/fwu.c line 93
Quoted 4 lines
lib/fwu_updates/fwu.c new file +4
-0+ ret =-1 ; +log_err ("Unable to delete TrialStateCtr variable\n" ); + } + }
Can we please move get/set variable into functions? Something like
- trial_counter_inc
- trial_counter_reset
Regards
/Ilias
Quoted 64 lines
lib/fwu_updates/fwu.c new file +61
-1+ +out: +free (mdata); +return ret; +} + +u8 fwu_update_checks_pass (void ) +{ +return !trial_state && boottime_check; +} + +int fwu_boottime_checks (void ) +{ +int ret; +u32 boot_idx, active_idx; + + ret =fwu_mdata_check (); +if (ret) { +return 0 ; + } + +/* +* Get the Boot Index, i.e. the bank from +* which the platform has booted. This value +* gets passed from the ealier stage bootloader +* which booted u-boot, e.g. tf-a. If the +* boot index is not the same as the +* active_index read from the FWU metadata, +* update the active_index. +*/ +fwu_plat_get_bootidx (&boot_idx); +if (boot_idx >=CONFIG_FWU_NUM_BANKS ) { +log_err ("Received incorrect value of boot_index\n" ); +return 0 ; + } + + ret =fwu_get_active_index (&active_idx); +if (ret) { +log_err ("Unable to read active_index\n" ); +return 0 ; + } + +if (boot_idx != active_idx) { +log_info ("Boot idx %u is not matching active idx %u, changing active_idx\n" , + boot_idx, active_idx); + ret =fwu_update_active_index (boot_idx); +if (!ret) + boottime_check =1 ; + +return 0 ; + } + +if (efi_init_obj_list () !=EFI_SUCCESS ) +return 0 ; + + ret =fwu_trial_state_check (); +if (!ret) + boottime_check =1 ; + +return 0 ; +} --2.34.1
Re: [PATCH v7 08/13] FWU: Add boot time checks as highlighted by the FWU specification
Hi Sughosh,
Quoted 12 lines
lib/fwu_updates/fwu.c line 45
Quoted 11 lines
lib/fwu_updates/fwu.c new file +10
-0+ nimages =CONFIG_FWU_NUM_IMAGES_PER_BANK ; + active_bank = mdata->active_index; + img_entry = &mdata->img_entry[0 ]; +for (i =0 ; i < nimages; i++) { + img_bank_info = &img_entry[i].img_bank_info[active_bank]; +if (!img_bank_info->accepted) { + trial_state =1 ; +break ; + } + }
Quoted 4 lines
Is this used elsewhere in the patchset? The function is starting to be big, so perhaps moving this in a static bool "
in_trial_state()" or similar would make it more readable.
There was a discussion about this on the synquacer thread for A/B updates. Once you split those in a function, it's better to extend the bootcount API with an EFI backed storage. The reasoning that a user might disable editing env variables for security reasons and that device might not be able to preserve RAM or store the counter in CPU registers across reboots.
If we extend the bootcount API with this code we can plug in the functionality seamlessly based on the hardware capabilities.
[...]
Regards
/Ilias
Re: [PATCH v7 08/13] FWU: Add boot time checks as highlighted by the FWU specification
hi Ilias,
Quoted 27 lines · Ilias Apalodimas
Hi Sughosh,
Quoted 12 lines
lib/fwu_updates/fwu.c line 45
Quoted 11 lines
lib/fwu_updates/fwu.c new file +10
-0+ nimages =CONFIG_FWU_NUM_IMAGES_PER_BANK ; + active_bank = mdata->active_index; + img_entry = &mdata->img_entry[0 ]; +for (i =0 ; i < nimages; i++) { + img_bank_info = &img_entry[i].img_bank_info[active_bank]; +if (!img_bank_info->accepted) { + trial_state =1 ; +break ; + } + }Quoted 4 lines
Is this used elsewhere in the patchset? The function is starting to be big, so perhaps moving this in a static bool "
in_trial_state()" or similar would make it more readable.There was a discussion about this on the synquacer thread for A/B updates. Once you split those in a function, it's better to extend the bootcount API with an EFI backed storage. The reasoning that a user might disable editing env variables for security reasons and that device might not be able to preserve RAM or store the counter in CPU registers across reboots.
Quoted 2 lines
If we extend the bootcount API with this code we can plug in the functionality seamlessly based on the hardware capabilities.
I have incorporated the rest of your comments on this patch. I moved the access to the TrialStateCtr EFI variable to the bootcount API like you suggested. However, I face an issue, in that on every boot, the bootdelay_process function gets called which increments the bootcount variable. This does not map with the requirement of the FWU feature since the TrialStateCtr variable needs to be updated only when the platform transitions to the Trial State, after a successful update. Once the platform transitions from the Trial State to the Regular State, the variable gets deleted. Hence I think it would be better to use the current logic of the handling of the TrialStateCtr variable. Thanks.
-sughosh
Quoted 6 lines
[...]
Regards
/Ilias
PATCH v7 9/13 FWU: Add support for the FWU Multi Bank Update feature
In reply to Sughosh GanuThe FWU Multi Bank Update feature supports updation of firmware images to one of multiple sets(also called banks) of images. The firmware images are clubbed together in banks, with the system booting images from the active bank. Information on the images such as which bank they belong to is stored as part of the metadata structure, which is stored on the same storage media as the firmware images on a dedicated partition.
At the time of update, the metadata is read to identify the bank to which the images need to be flashed(update bank). On a successful update, the metadata is modified to set the updated bank as active bank to subsequently boot from.
---
Changes since V6: None
include/fwu.h | 10 ++ 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 | 3 +- lib/fwu_updates/fwu.c | 26 ++++ 8 files changed, 304 insertions(+), 7 deletions(-) create mode 100644 lib/fwu_updates/Kconfig
include/fwu.h +10 -0
@@ -32,13 +32,23 @@ struct fwu_mdata_ops { };#define FWU_MDATA_VERSION 0x1 +#define FWU_IMAGE_ACCEPTED 0x1#define FWU_MDATA_GUID \ EFI_GUID(0x8a7a84a0, 0x8387, 0x40f6, 0xab, 0x41, \ 0xa8, 0xb9, 0xa5, 0xa6, 0x0d, 0x23) +#define FWU_OS_REQUEST_FW_REVERT_GUID \ + EFI_GUID(0xacd58b4b, 0xc0e8, 0x475f, 0x99, 0xb5, \ + 0x6b, 0x3f, 0x7e, 0x07, 0xaa, 0xf0) + +#define FWU_OS_REQUEST_FW_ACCEPT_GUID \ + EFI_GUID(0x0c996046, 0xbcc0, 0x4d04, 0x85, 0xec, \ + 0xe1, 0xfc, 0xed, 0xf1, 0xc6, 0xf8) +u8 fwu_update_checks_pass (void );int fwu_boottime_checks (void ); +int fwu_trial_state_ctr_start (void );int fwu_get_mdata (struct fwu_mdata **mdata);int fwu_update_mdata (struct fwu_mdata *mdata);
lib/Kconfig +6 -0
@@ -967,3 +967,9 @@ config LMB_RESERVED_REGIONS memory blocks. endmenu + +menu "FWU Multi Bank Updates" + +source lib/fwu_updates/Kconfig + +endmenu
lib/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_EFI) += efi/ obj-$(CONFIG_EFI_LOADER) += efi_driver/ obj-$(CONFIG_EFI_LOADER) += efi_loader/ obj-$(CONFIG_CMD_BOOTEFI_SELFTEST) += efi_selftest/ +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu_updates/ obj-$(CONFIG_LZMA) += lzma/ obj-$(CONFIG_BZIP2) += bzip2/ obj-$(CONFIG_FIT) += libfdt/
lib/efi_loader/efi_capsule.c +226 -5
308 lines not on this page · raw message
lib/efi_loader/efi_setup.c +2 -1
@@ -350,7 +350,8 @@ efi_status_t efi_init_obj_list(void) goto out;/* Execute capsules after reboot */ -if (IS_ENABLED (CONFIG_EFI_CAPSULE_ON_DISK ) && +if (!IS_ENABLED (CONFIG_FWU_MULTI_BANK_UPDATE ) && +IS_ENABLED (CONFIG_EFI_CAPSULE_ON_DISK ) && !IS_ENABLED (CONFIG_EFI_CAPSULE_ON_DISK_EARLY )) ret =efi_launch_capsules (); out:
lib/fwu_updates/Kconfig new file +31 -0
@@ -0,0 +1,31 @@ +config FWU_MULTI_BANK_UPDATE + bool "Enable FWU Multi Bank Update Feature" + depends on EFI_HAVE_CAPSULE_SUPPORT + select PARTITION_TYPE_GUID + select EFI_SETUP_EARLY + help + Feature for updating firmware images on platforms having + multiple banks(copies) of the firmware images. One of the + bank is selected for updating all the firmware components + +config FWU_NUM_BANKS + int "Number of Banks defined by the platform" + depends on FWU_MULTI_BANK_UPDATE + help + Define the number of banks of firmware images on a platform + +config FWU_NUM_IMAGES_PER_BANK + int "Number of firmware images per bank" + depends on FWU_MULTI_BANK_UPDATE + help + Define the number of firmware images per bank. This value + should be the same for all the banks. + +config FWU_TRIAL_STATE_CNT + int "Number of times system boots in Trial State" + depends on FWU_MULTI_BANK_UPDATE + default 3 + help + With FWU Multi Bank Update feature enabled, number of times + the platform is allowed to boot in Trial State after an + update.
lib/fwu_updates/Makefile +2 -1
@@ -1,6 +1,7 @@ -# SPDX-License-Identifier: GPL-2.0+ +# SPDX-License-Identifier: GPL-2.0-or-later # # Copyright (c) 2022, Linaro Limited # +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu.o obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_gpt.o
lib/fwu_updates/fwu.c +26 -0
@@ -113,6 +113,32 @@ u8 fwu_update_checks_pass(void)return !trial_state && boottime_check; } +int fwu_trial_state_ctr_start (void ) +{ +int ret; +u32 var_attributes; +efi_status_t status; +efi_uintn_t var_size; +u16 trial_state_ctr; + + var_size = (efi_uintn_t )sizeof (trial_state_ctr); + var_attributes =EFI_VARIABLE_NON_VOLATILE | +EFI_VARIABLE_BOOTSERVICE_ACCESS ; + + trial_state_ctr = ret =0 ; + status =efi_set_variable_int (u"TrialStateCtr" , + &efi_global_variable_guid, + var_attributes, + var_size, + &trial_state_ctr, false); +if (status !=EFI_SUCCESS ) { +log_err ("Unable to increment TrialStateCtr variable\n" ); + ret =-1 ; + } + +return ret; +} +int fwu_boottime_checks (void ) {int ret;
Signature · 1 line
2.34.1
Re: [PATCH v7 09/13] FWU: Add support for the FWU Multi Bank Update feature
Hi Sughosh,
[...]
Quoted 27 lines
#endif /*
CONFIG_EFI_CAPSULE_AUTHENTICATE*/lib/efi_loader/efi_capsule.c +25
-0+static bool fwu_empty_capsule (struct efi_capsule_header *capsule) +{ +return !guidcmp (&capsule->capsule_guid, + &fwu_guid_os_request_fw_revert) || + !guidcmp (&capsule->capsule_guid, + &fwu_guid_os_request_fw_accept); +} + +static efi_status_t fwu_empty_capsule_process ( +struct efi_capsule_header *capsule) +{ +int status; +u32 active_idx; +efi_status_t ret; +efi_guid_t *image_guid; + +if (!guidcmp (&capsule->capsule_guid, + &fwu_guid_os_request_fw_revert)) { +/* +* One of the previously updated image has +* failed the OS acceptance test. OS has +* requested to revert back to the earlier +* boot index +*/ + status =fwu_revert_boot_index ();
lib/efi_loader/efi_capsule.c efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t capsule_s · line 438
Quoted 10 lines
lib/efi_loader/efi_capsule.c +10
-0+if (status <0 ) { +log_err ("Failed to revert the FWU boot index\n" ); +if (status == -ENODEV || + status == -ERANGE || + status == -EIO ) + ret =EFI_DEVICE_ERROR ; +else if (status == -EINVAL ) + ret =EFI_INVALID_PARAMETER ; +else + ret =EFI_OUT_OF_RESOURCES ;
In all the case you carry those if statements, define a function like
static efi_status_t fwu_to_efi_error (int err)
{
switch(err) {
case -ENODEV:
case -ERANGE:
case -EIO:
return EFI_DEVICE_ERROR;
}
.....
}and use it in the error handling below.
That should make the weird looking error handling go away and adding more cases in the future a lot easier.
lib/efi_loader/efi_capsule.c efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t capsule_s · line 441
Quoted 3 lines
lib/efi_loader/efi_capsule.c +3
-0+ }else { + ret =EFI_SUCCESS ; +log_err ("Reverted the FWU active_index. Recommend rebooting the system\n" );
Does it really need log_err?
[...]
Regards
/Ilias
PATCH v7 10/13 FWU: cmd: Add a command to read FWU metadata
In reply to Sughosh GanuAdd a command to read the metadata as specified in the FWU specification and print the fields of the metadata.
---
Changes since V6: None
cmd/Kconfig | 7 +++++ cmd/Makefile | 1 + cmd/fwu_mdata.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 cmd/fwu_mdata.c
cmd/Kconfig +7 -0
@@ -161,6 +161,13 @@ config CMD_CPU internal name) and clock frequency. Other information may be available depending on the CPU driver. +config CMD_FWU_METADATA + bool "fwu metadata read" + depends on FWU_MULTI_BANK_UPDATE + default y + help + Command to read the metadata and dump it's contents + config CMD_LICENSE bool "license" select BUILD_BIN2C
cmd/Makefile +1 -0
@@ -76,6 +76,7 @@ obj-$(CONFIG_CMD_FPGA) += fpga.o obj-$(CONFIG_CMD_FPGAD) += fpgad.o obj-$(CONFIG_CMD_FS_GENERIC) += fs.o obj-$(CONFIG_CMD_FUSE) += fuse.o +obj-$(CONFIG_CMD_FWU_METADATA) += fwu_mdata.o obj-$(CONFIG_CMD_GETTIME) += gettime.o obj-$(CONFIG_CMD_GPIO) += gpio.o obj-$(CONFIG_CMD_HVC) += smccc.o
cmd/fwu_mdata.c new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v7 10/13] FWU: cmd: Add a command to read FWU metadata
Quoted 131 lines · Sughosh Ganu
Add a command to read the metadata as specified in the FWU specification and print the fields of the metadata.
Signed-off-by Sughosh Ganu <[email protected]>---
Changes since V6: Nonecmd/Kconfig | 7 +++++ cmd/Makefile | 1 + cmd/fwu_mdata.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 cmd/fwu_mdata.ccmd/Kconfig +7
-0@@ -161,6 +161,13 @@ config CMD_CPU internal name) and clock frequency. Other information may be available depending on the CPU driver. +config CMD_FWU_METADATA + bool "fwu metadata read" + depends on FWU_MULTI_BANK_UPDATE + default y + help + Command to read the metadata and dump it's contents + config CMD_LICENSE bool "license" select BUILD_BIN2Ccmd/Makefile +1
-0@@ -76,6 +76,7 @@ obj-$(CONFIG_CMD_FPGA) += fpga.o obj-$(CONFIG_CMD_FPGAD) += fpgad.o obj-$(CONFIG_CMD_FS_GENERIC) += fs.o obj-$(CONFIG_CMD_FUSE) += fuse.o +obj-$(CONFIG_CMD_FWU_METADATA) += fwu_mdata.o obj-$(CONFIG_CMD_GETTIME) += gettime.o obj-$(CONFIG_CMD_GPIO) += gpio.o obj-$(CONFIG_CMD_HVC) += smccc.ocmd/fwu_mdata.c new file +80
-1@@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (c) 2022, Linaro Limited +*/ + +#include <command.h> +#include <dm.h> +#include <fwu.h> +#include <fwu_mdata.h> +#include <log.h> +#include <stdio.h> +#include <stdlib.h> + +#include <linux/types.h> + +static void print_mdata (struct fwu_mdata *mdata) +{ +int i, j; +struct fwu_image_entry *img_entry; +struct fwu_image_bank_info *img_info; + +printf ("\tFWU Metadata\n" ); +printf ("crc32: %#x\n" , mdata->crc32); +printf ("version: %#x\n" , mdata->version); +printf ("active_index: %#x\n" , mdata->active_index); +printf ("previous_active_index: %#x\n" , mdata->previous_active_index); + +printf ("\tImage Info\n" ); +for (i =0 ; i <CONFIG_FWU_NUM_IMAGES_PER_BANK ; i++) { + img_entry = &mdata->img_entry[i]; +printf ("\nImage Type Guid: %pUL\n" , + &img_entry->image_type_uuid); +printf ("Location Guid: %pUL\n" , &img_entry->location_uuid); +for (j =0 ; j <CONFIG_FWU_NUM_BANKS ; j++) { + img_info = &img_entry->img_bank_info[j]; +printf ("Image Guid: %pUL\n" , &img_info->image_uuid); +printf ("Image Acceptance: %s\n" , + img_info->accepted ==0x1 ?"yes" :"no" ); + } + } +} + +int do_fwu_mdata_read (struct cmd_tbl *cmdtp,int flag, +int argc,char *const argv[]) +{ +struct udevice *dev; +int ret =CMD_RET_SUCCESS , res; +struct fwu_mdata *mdata =NULL ; + +if (uclass_get_device (UCLASS_FWU_MDATA ,0 , &dev) || !dev) { +log_err ("Unable to get FWU metadata device\n" ); +return CMD_RET_FAILURE ; + } + + res =fwu_mdata_check (); +if (res <0 ) { +log_err ("FWU Metadata check failed\n" ); + ret =CMD_RET_FAILURE ; + goto out; + } + + res =fwu_get_mdata (&mdata); +if (res <0 ) { +log_err ("Unable to get valid FWU metadata\n" ); + ret =CMD_RET_FAILURE ; + goto out; + } + +print_mdata (mdata); + +out: +free (mdata); +return ret; +} + +U_BOOT_CMD ( + fwu_mdata_read,1 ,1 , do_fwu_mdata_read, +"Read and print FWU metadata" , +"" +); --
Quoted 2 lines
2.34.1
PATCH v7 11/13 mkeficapsule: Add support for generating empty capsules
In reply to Sughosh GanuThe Dependable Boot specification[1] describes the structure of the firmware accept and revert capsules. These are empty capsules which are used for signalling the acceptance or rejection of the updated firmware by the OS. Add support for generating these empty capsules.
---
Changes since V6: None
doc/mkeficapsule.1 | 29 ++++++++++---- tools/eficapsule.h | 8 ++++ tools/mkeficapsule.c | 92 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 115 insertions(+), 14 deletions(-)
doc/mkeficapsule.1 +22 -7
@@ -8,7 +8,7 @@ mkeficapsule \- Generate EFI capsule file for U-Boot .SH SYNOPSIS .B mkeficapsule -.RI [ options "] " image-blob " " capsule-file +.RI [ options ] " " [ image-blob ] " " capsule-file .SH "DESCRIPTION" .B mkeficapsule
@@ -23,8 +23,13 @@ Optionally, a capsule file can be signed with a given private key. In this case, the update will be authenticated by verifying the signature before applying. +Additionally, an empty capsule file can be generated for acceptance or +rejection of firmware images by a governing component like an Operating +System. The empty capsules do not require an image-blob input file. + + .B mkeficapsule -takes any type of image files, including: +takes any type of image files when generating non empty capsules, including: .TP .I raw image format is a single binary blob of any type of firmware.
@@ -36,18 +41,16 @@ multiple binary blobs in a single capsule file. This type of image file can be generated by .BR mkimage . -.PP -If you want to use other types than above two, you should explicitly -specify a guid for the FMP driver. - .SH "OPTIONS" + .TP .BI "-g\fR,\fB --guid " guid-string Specify guid for image blob type. The format is: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx The first three elements are in little endian, while the rest -is in big endian. +is in big endian. The option must be specified for all non empty and +image acceptance capsules .TP .BI "-i\fR,\fB --index " index
@@ -57,6 +60,18 @@ Specify an image index .BI "-I\fR,\fB --instance " instance Specify a hardware instance +.PP +For generation of firmware accept empty capsule +.BR --guid +is mandatory +.TP +.BI "-A\fR,\fB --fw-accept " +Generate a firmware acceptance empty capsule + +.TP +.BI "-R\fR,\fB --fw-revert " +Generate a firmware revert empty capsule + .TP .BR -h ", " --help Print a help message
tools/eficapsule.h +8 -0
@@ -41,6 +41,14 @@ typedef struct {EFI_GUID (0x4aafd29d ,0x68df ,0x49ee ,0x8a ,0xa9 , \ 0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7) +#define FW_ACCEPT_OS_GUID \ + EFI_GUID(0x0c996046, 0xbcc0, 0x4d04, 0x85, 0xec, \ + 0xe1, 0xfc, 0xed, 0xf1, 0xc6, 0xf8) + +#define FW_REVERT_OS_GUID \ + EFI_GUID(0xacd58b4b, 0xc0e8, 0x475f, 0x99, 0xb5, \ + 0x6b, 0x3f, 0x7e, 0x07, 0xaa, 0xf0) +/* flags */ #define CAPSULE_FLAGS_PERSIST_ACROSS_RESET 0x00010000
tools/mkeficapsule.c +85 -7
138 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v7 11/13] mkeficapsule: Add support for generating empty capsules
Hi Sughosh,
Quoted 9 lines · Sughosh Ganu
The Dependable Boot specification[1] describes the structure of the firmware accept and revert capsules. These are empty capsules which are used for signalling the acceptance or rejection of the updated firmware by the OS. Add support for generating these empty capsules.
Signed-off-by Sughosh Ganu <[email protected]>
[...]
Quoted 5 lines
tools/mkeficapsule.c +1
-0+ capsule_type =CAPSULE_NORMAL_BLOB ;for (;;) { c =getopt_long (argc, argv, opts_short, options, &idx);if (c ==-1 )
tools/mkeficapsule.c int main(int argc, char **argv) · line 701
Quoted 10 lines
tools/mkeficapsule.c +6
-1@@ -639,22 +693,46 @@ int main(int argc, char **argv)case 'd' : dump_sig =1 ;break ; -case 'h' : +case 'A' : + capsule_type |=CAPSULE_ACCEPT ; +break ; +case 'R' : + capsule_type |=CAPSULE_REVERT ; +break ;
capsule_type will be set to CAPSULE_NORMAL_BLOB. I think it's better to have case 'A':
if (capsule_type)
//error out mentioned A and R are mutually exclusive
capsule_type = CAPSULE_ACCEPT;
break;
case 'R':
if (capsule_type)
//error out mentioned A and R are mutually exclusive
capsule_type |= CAPSULE_REVERT;
break;tools/mkeficapsule.c int main(int argc, char **argv) · line 713
Quoted 12 lines
tools/mkeficapsule.c +7
-0+default :print_usage ();exit (EXIT_SUCCESS ); } } +if (capsule_type == (CAPSULE_ACCEPT |CAPSULE_REVERT )) { +fprintf (stderr, +"Select either of Accept or Revert capsule generation\n" ); +exit (EXIT_FAILURE ); + } +
And get rid of this if
[...]
Regards
/Ilias
PATCH v7 12/13 mkeficapsule: Add support for setting OEM flags in capsule header
In reply to Sughosh GanuAdd support for setting OEM flags in the capsule header. As per the UEFI specification, bits 0-15 of the flags member of the capsule header can be defined per capsule GUID.
The oemflags will be used for the FWU Multi Bank update feature, as specified by the Dependable Boot specification[1]. Bit 15 of the flags member will be used to determine if the acceptance/rejection of the updated images is to be done by the firmware or an external component like the OS.
---
Changes since V6: None
doc/mkeficapsule.1 | 4 ++++ tools/mkeficapsule.c | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-)
doc/mkeficapsule.1 +4 -0
@@ -72,6 +72,10 @@ Generate a firmware acceptance empty capsule .BI "-R\fR,\fB --fw-revert " Generate a firmware revert empty capsule +.TP +.BI "-o\fR,\fB --capoemflag " +Capsule OEM flag, value between 0x0000 to 0xffff + .TP .BR -h ", " --help Print a help message
tools/mkeficapsule.c +14 -3
@@ -29,7 +29,7 @@ static const char *tool_name = "mkeficapsule";efi_guid_t efi_guid_fm_capsule =EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID ;efi_guid_t efi_guid_cert_type_pkcs7 =EFI_CERT_TYPE_PKCS7_GUID ; -static const char *opts_short ="g:i:I:v:p:c:m:dhAR" ; +static const char *opts_short ="g:i:I:v:p:c:m:o:dhAR" ;enum {CAPSULE_NORMAL_BLOB =0 ,
@@ -47,6 +47,7 @@ static struct option options[] = { {"dump-sig", no_argument, NULL, 'd'}, {"fw-accept", no_argument, NULL, 'A'}, {"fw-revert", no_argument, NULL, 'R'}, + {"capoemflag", required_argument, NULL, 'o'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}, };
@@ -65,6 +66,7 @@ static void print_usage(void)"\t-d, --dump_sig dump signature (*.p7)\n" "\t-A, --fw-accept firmware accept capsule, requires GUID, no image blob\n" "\t-R, --fw-revert firmware revert capsule, takes no GUID, no image blob\n" +"\t-o, --capoemflag Capsule OEM Flag, an integer between 0x0000 and 0xffff\n" "\t-h, --help print a help message\n" , tool_name); }
@@ -387,6 +389,7 @@ static void free_sig_data(struct auth_context *ctx)* @mcount: Monotonic count in authentication information * @private_file: Path to a private key file * @cert_file: Path to a certificate file +* @oemflags: Capsule OEM Flags, bits 0-15 * * This function actually does the job of creating an uefi capsule file. * All the arguments must be supplied.
@@ -399,7 +402,8 @@ static void free_sig_data(struct auth_context *ctx)*/ static int create_fwbin (char *path,char *bin,efi_guid_t *guid,unsigned long index,unsigned long instance, -uint64_t mcount,char *privkey_file,char *cert_file) +uint64_t mcount,char *privkey_file,char *cert_file, +uint16_t oemflags) {struct efi_capsule_header header;struct efi_firmware_management_capsule_header capsule;
@@ -464,6 +468,8 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid, header.header_size =sizeof (header);/* TODO: The current implementation ignores flags */ header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ; +if (oemflags) + header.flags |= oemflags; header.capsule_image_size =sizeof (header) +sizeof (capsule) +sizeof (uint64_t ) +sizeof (image)
@@ -635,6 +641,7 @@ int main(int argc, char **argv)unsigned char uuid_buf[16 ];unsigned long index, instance;uint64_t mcount; +uint16_t oemflags;char *privkey_file, *cert_file;int c, idx;
@@ -646,6 +653,7 @@ int main(int argc, char **argv) cert_file =NULL ; dump_sig =0 ; capsule_type =CAPSULE_NORMAL_BLOB ; + oemflags =0 ;for (;;) { c =getopt_long (argc, argv, opts_short, options, &idx);if (c ==-1 )
@@ -699,6 +707,9 @@ int main(int argc, char **argv)case 'R' : capsule_type |=CAPSULE_REVERT ;break ; +case 'o' : + oemflags =strtoul (optarg,NULL ,0 ); +break ;default :print_usage ();exit (EXIT_SUCCESS );
@@ -732,7 +743,7 @@ int main(int argc, char **argv) } }else if (create_fwbin (argv[argc -1 ], argv[argc -2 ], guid, index, instance, mcount, privkey_file, - cert_file) <0 ) { + cert_file, oemflags) <0 ) {fprintf (stderr,"Creating firmware capsule failed\n" );exit (EXIT_FAILURE ); }
Signature · 1 line
2.34.1
Re: [PATCH v7 12/13] mkeficapsule: Add support for setting OEM flags in capsule header
Hi Sughosh,
Quoted 10 lines · Sughosh Ganu
Add support for setting OEM flags in the capsule header. As per the UEFI specification, bits 0-15 of the flags member of the capsule header can be defined per capsule GUID.
The oemflags will be used for the FWU Multi Bank update feature, as specified by the Dependable Boot specification[1]. Bit 15 of the flags member will be used to determine if the acceptance/rejection of the updated images is to be done by the firmware or an external component like the OS.
Have we documented bit15 in the documentation? If not please add it.
Quoted 118 lines
Signed-off-by Sughosh Ganu <[email protected]>---
Changes since V6: Nonedoc/mkeficapsule.1 | 4 ++++ tools/mkeficapsule.c | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-)doc/mkeficapsule.1 +4
-0@@ -72,6 +72,10 @@ Generate a firmware acceptance empty capsule .BI "-R\fR,\fB --fw-revert " Generate a firmware revert empty capsule +.TP +.BI "-o\fR,\fB --capoemflag " +Capsule OEM flag, value between 0x0000 to 0xffff + .TP .BR -h ", " --help Print a help messagetools/mkeficapsule.c +14
-4@@ -29,7 +29,7 @@ static const char *tool_name = "mkeficapsule";efi_guid_t efi_guid_fm_capsule =EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID ;efi_guid_t efi_guid_cert_type_pkcs7 =EFI_CERT_TYPE_PKCS7_GUID ; -static const char *opts_short ="g:i:I:v:p:c:m:dhAR" ; +static const char *opts_short ="g:i:I:v:p:c:m:o:dhAR" ;enum {CAPSULE_NORMAL_BLOB =0 ,@@ -47,6 +47,7 @@ static struct option options[] = { {"dump-sig", no_argument, NULL, 'd'}, {"fw-accept", no_argument, NULL, 'A'}, {"fw-revert", no_argument, NULL, 'R'}, + {"capoemflag", required_argument, NULL, 'o'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}, };@@ -65,6 +66,7 @@ static void print_usage(void)"\t-d, --dump_sig dump signature (*.p7)\n" "\t-A, --fw-accept firmware accept capsule, requires GUID, no image blob\n" "\t-R, --fw-revert firmware revert capsule, takes no GUID, no image blob\n" +"\t-o, --capoemflag Capsule OEM Flag, an integer between 0x0000 and 0xffff\n" "\t-h, --help print a help message\n" , tool_name); }@@ -387,6 +389,7 @@ static void free_sig_data(struct auth_context *ctx)* @mcount: Monotonic count in authentication information * @private_file: Path to a private key file * @cert_file: Path to a certificate file +* @oemflags: Capsule OEM Flags, bits 0-15 * * This function actually does the job of creating an uefi capsule file. * All the arguments must be supplied. @@ -399,7 +402,8 @@ static void free_sig_data(struct auth_context *ctx)*/ static int create_fwbin (char *path,char *bin,efi_guid_t *guid,unsigned long index,unsigned long instance, -uint64_t mcount,char *privkey_file,char *cert_file) +uint64_t mcount,char *privkey_file,char *cert_file, +uint16_t oemflags) {struct efi_capsule_header header;struct efi_firmware_management_capsule_header capsule;@@ -464,6 +468,8 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid, header.header_size =sizeof (header);/* TODO: The current implementation ignores flags */ header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ; +if (oemflags) + header.flags |= oemflags; header.capsule_image_size =sizeof (header) +sizeof (capsule) +sizeof (uint64_t ) +sizeof (image)@@ -635,6 +641,7 @@ int main(int argc, char **argv)unsigned char uuid_buf[16 ];unsigned long index, instance;uint64_t mcount; +uint16_t oemflags;char *privkey_file, *cert_file;int c, idx;@@ -646,6 +653,7 @@ int main(int argc, char **argv) cert_file =NULL ; dump_sig =0 ; capsule_type =CAPSULE_NORMAL_BLOB ; + oemflags =0 ;for (;;) { c =getopt_long (argc, argv, opts_short, options, &idx);if (c ==-1 )@@ -699,6 +707,9 @@ int main(int argc, char **argv)case 'R' : capsule_type |=CAPSULE_REVERT ;break ; +case 'o' : + oemflags =strtoul (optarg,NULL ,0 ); +break ;default :print_usage ();exit (EXIT_SUCCESS );@@ -732,7 +743,7 @@ int main(int argc, char **argv) } }else if (create_fwbin (argv[argc -1 ], argv[argc -2 ], guid, index, instance, mcount, privkey_file, - cert_file) <0 ) { + cert_file, oemflags) <0 ) {fprintf (stderr,"Creating firmware capsule failed\n" );exit (EXIT_FAILURE ); } --
Quoted 2 lines
2.34.1
Re: [PATCH v7 12/13] mkeficapsule: Add support for setting OEM flags in capsule header
hi Ilias,
Quoted 9 lines · Ilias Apalodimas
Hi Sughosh,
Quoted 5 lines · Sughosh Ganu
Add support for setting OEM flags in the capsule header. As per the UEFI specification, bits 0-15 of the flags member of the capsule header can be defined per capsule GUID.
Quoted 7 lines
Quoted 5 lines
The oemflags will be used for the FWU Multi Bank update feature, as specified by the Dependable Boot specification[1]. Bit 15 of the flags member will be used to determine if the acceptance/rejection of the updated images is to be done by the firmware or an external component like the OS.
Have we documented bit15 in the documentation? If not please add it.
Yes, the use of bit15 has been added in the documentation for this feature. I will incorporate all your review comments, and in case I hit any issues while incorporating any review comment, I will respond to that. Thanks for the review.
-sughosh
Quoted 123 lines
Quoted 119 lines
Signed-off-by Sughosh Ganu <[email protected]>---
Changes since V6: Nonedoc/mkeficapsule.1 | 4 ++++ tools/mkeficapsule.c | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-)doc/mkeficapsule.1 +4
-0@@ -72,6 +72,10 @@ Generate a firmware acceptance empty capsule .BI "-R\fR,\fB --fw-revert " Generate a firmware revert empty capsule +.TP +.BI "-o\fR,\fB --capoemflag " +Capsule OEM flag, value between 0x0000 to 0xffff + .TP .BR -h ", " --help Print a help messagetools/mkeficapsule.c +14
-4@@ -29,7 +29,7 @@ static const char *tool_name = "mkeficapsule";efi_guid_t efi_guid_fm_capsule =EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID ;efi_guid_t efi_guid_cert_type_pkcs7 =EFI_CERT_TYPE_PKCS7_GUID ; -static const char *opts_short ="g:i:I:v:p:c:m:dhAR" ; +static const char *opts_short ="g:i:I:v:p:c:m:o:dhAR" ;enum {CAPSULE_NORMAL_BLOB =0 ,@@ -47,6 +47,7 @@ static struct option options[] = { {"dump-sig", no_argument, NULL, 'd'}, {"fw-accept", no_argument, NULL, 'A'}, {"fw-revert", no_argument, NULL, 'R'}, + {"capoemflag", required_argument, NULL, 'o'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}, };@@ -65,6 +66,7 @@ static void print_usage(void)"\t-d, --dump_sig dump signature (*.p7)\n" "\t-A, --fw-accept firmware accept capsule, requires GUID, no image blob\n" "\t-R, --fw-revert firmware revert capsule, takes no GUID, no image blob\n" +"\t-o, --capoemflag Capsule OEM Flag, an integer between 0x0000 and 0xffff\n" "\t-h, --help print a help message\n" , tool_name); }@@ -387,6 +389,7 @@ static void free_sig_data(struct auth_context *ctx)* @mcount: Monotonic count in authentication information * @private_file: Path to a private key file * @cert_file: Path to a certificate file +* @oemflags: Capsule OEM Flags, bits 0-15 * * This function actually does the job of creating an uefi capsule file. * All the arguments must be supplied. @@ -399,7 +402,8 @@ static void free_sig_data(struct auth_context *ctx)*/ static int create_fwbin (char *path,char *bin,efi_guid_t *guid,unsigned long index,unsigned long instance, -uint64_t mcount,char *privkey_file,char *cert_file) +uint64_t mcount,char *privkey_file,char *cert_file, +uint16_t oemflags) {struct efi_capsule_header header;struct efi_firmware_management_capsule_header capsule;@@ -464,6 +468,8 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid, header.header_size =sizeof (header);/* TODO: The current implementation ignores flags */ header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ; +if (oemflags) + header.flags |= oemflags; header.capsule_image_size =sizeof (header) +sizeof (capsule) +sizeof (uint64_t ) +sizeof (image)@@ -635,6 +641,7 @@ int main(int argc, char **argv)unsigned char uuid_buf[16 ];unsigned long index, instance;uint64_t mcount; +uint16_t oemflags;char *privkey_file, *cert_file;int c, idx;@@ -646,6 +653,7 @@ int main(int argc, char **argv) cert_file =NULL ; dump_sig =0 ; capsule_type =CAPSULE_NORMAL_BLOB ; + oemflags =0 ;for (;;) { c =getopt_long (argc, argv, opts_short, options, &idx);if (c ==-1 )@@ -699,6 +707,9 @@ int main(int argc, char **argv)case 'R' : capsule_type |=CAPSULE_REVERT ;break ; +case 'o' : + oemflags =strtoul (optarg,NULL ,0 ); +break ;default :print_usage ();exit (EXIT_SUCCESS );@@ -732,7 +743,7 @@ int main(int argc, char **argv) } }else if (create_fwbin (argv[argc -1 ], argv[argc -2 ], guid, index, instance, mcount, privkey_file, - cert_file) <0 ) { + cert_file, oemflags) <0 ) {fprintf (stderr,"Creating firmware capsule failed\n" );exit (EXIT_FAILURE ); } --Quoted 2 lines
2.34.1
Reviewed-by Ilias Apalodimas <[email protected]>
PATCH v7 13/13 FWU: doc: Add documentation for the FWU feature
In reply to Sughosh GanuAdd documentattion for the FWU Multi Bank Update feature. The document describes the steps needed for setting up the platform for the feature, as well as steps for enabling the feature on the platform.
---
Changes since V6: None
doc/develop/uefi/fwu_updates.rst | 156 +++++++++++++++++++++++++++++++ doc/develop/uefi/index.rst | 1 + doc/develop/uefi/uefi.rst | 2 + 3 files changed, 159 insertions(+) create mode 100644 doc/develop/uefi/fwu_updates.rst
doc/develop/uefi/fwu_updates.rst new file +156 -0
@@ -0,0 +1,156 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright (c) 2022 Linaro Limited + +FWU Multi Bank Updates in U-Boot +================================ + +The FWU Multi Bank Update feature implements the firmware update +mechanism described in the PSA Firmware Update for A-profile Arm +Architecture specification[1]. Certain aspects of the Dependable +Boot specification[2] are also implemented. The feature provides a +mechanism to have multiple banks of updatable firmware images and for +updating the firmware images on the non-booted bank. On a successful +update, the platform boots from the updated bank on subsequent +boot. The UEFI capsule-on-disk update feature is used for performing +the actual updates of the updatable firmware images. + +The bookkeeping of the updatable images is done through a structure +called metadata. Currently, the FWU metadata supports identification +of images based on image GUIDs stored on a GPT partitioned storage +media. There are plans to extend the metadata structure for non GPT +partitioned devices as well. + +Accessing the FWU metadata is done through generic API's which are +defined in a driver which complies with the u-boot's driver model. A +new uclass UCLASS_FWU_MDATA has been added for accessing the FWU +metadata. Individual drivers can be added based on the type of storage +media, and it's partitioning method. Details of the storage device +containing the FWU metadata partitions are specified through a U-Boot +specific device tree property `fwu-mdata-store`. Please refer to +U-Boot `doc <doc/device-tree-bindings/firmware/fwu-mdata.txt>`__ for +the device tree bindings. + +Enabling the FWU Multi Bank Update feature +------------------------------------------ + +The feature can be enabled by specifying the following configs:: + + CONFIG_EFI_CAPSULE_ON_DISK=y + CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT=y + CONFIG_EFI_CAPSULE_FIRMWARE=y + CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y + + CONFIG_FWU_MULTI_BANK_UPDATE=y + CONFIG_CMD_FWU_METADATA=y + CONFIG_DM_FWU_MDATA=y + CONFIG_FWU_MDATA_GPT_BLK=y + CONFIG_FWU_NUM_BANKS=<val> + CONFIG_FWU_NUM_IMAGES_PER_BANK=<val> + +in the .config file + +The first group of configs enable the UEFI capsule-on-disk update +functionality. The second group of configs enable the FWU Multi Bank +Update functionality. Please refer to the section +:ref:`uefi_capsule_update_ref` for more details on generation of the +UEFI capsule. + +Setting up the device for GPT partitioned storage +------------------------------------------------- + +Before enabling the functionality in U-Boot, certain changes are +required to be done on the storage device. Assuming a GPT partitioned +storage device, the storage media needs to be partitioned with the +correct number of partitions, given the number of banks and number of +images per bank that the platform is going to support. Each updatable +firmware image will be stored on an separate partition. In addition, +the two copies of the FWU metadata will be stored on two separate +partitions. + +As an example, a platform supporting two banks with each bank +containing three images would need to have 2 * 3 = 6 parititions plus +the two metadata partitions, or 8 partitions. In addition the storage +media can have additional partitions of non-updatable images, like the +EFI System Partition(ESP), a partition for the root file system etc. + +When generating the partitions, a few aspects need to be taken care +of. Each GPT partition entry in the GPT header has two GUIDs:: + + *PartitionTypeGUID* + *UniquePartitionGUID* + +The PartitionTypeGUID value should correspond to the *image_type_uuid* +field of the FWU metadata. This field is used to identify a given type +of updatable firmware image, e.g. u-boot, op-tee, FIP etc. This GUID +should also be used for specifying the `--guid` parameter when +generating the capsule. + +The UniquePartitionGUID value should correspond to the *image_uuid* +field in the FWU metadata. This GUID is used to identify images of a +given image type in different banks. + +Similarly, the FWU specifications defines the GUID value to be used +for the metadata partitions. This would be the PartitionTypeGUID for +the metadata partitions. + +When generating the metadata, the *image_type_uuid* and the +*image_uuid* values should match the *PartitionTypeGUID* and the +*UniquePartitionGUID* values respectively. + +Performing the Update +--------------------- + +Once the storage media has been partitioned and populated with the +metadata partitions, the UEFI capsule-on-disk update functionality can +be used for performing the update. Refer to the section +:ref:`uefi_capsule_update_ref` for details on how the update can be +invoked. + +On a successful update, the FWU metadata gets updated to reflect the +bank from which the platform would be booting on subsequent boot. + +Based on the value of bit15 of the Flags member of the capsule header, +the updated images would either be accepted by the u-boot's UEFI +implementation, or by the Operating System. If the Operating System is +accepting the firmware images, it does so by generating an empty +*accept* capsule. The Operating System can also reject the updated +firmware by generating a *revert* capsule. The empty capsule can be +applied by using the exact same procedure used for performing the +capsule-on-disk update. + +The task of accepting the different firmware images, post an update +may be done by multiple, separate components in the Operating +System. To help identify the firmware image that is being accepted, +the accept capsule passes the image GUID of the firmware image being +accepted. The relevant code in u-boot then sets the Accept bit of the +corresponding firmware image for which the accept capsule was +found. Only when all the firmware components in a bank have been +accepted does the platform transition to the regular state from trial +state. + +The revert capsule on the other hand does not pass any image GUID, +since reverting any image of the bank has the same result of the +platform booting from the other bank on subsequent boot. + +Generating an empty capsule +--------------------------- + +The empty capsule can be generated using the mkeficapsule utility. To +build the tool, enable:: + + CONFIG_TOOLS_MKEFICAPSULE=y + +Run the following commands to generate the accept/revert capsules:: + +.. code-block:: bash + + $ ./tools/mkeficapsule \ + [--fw-accept --guid <image guid>] | \ + [--fw-revert] \ + <capsule_file_name> + +Links +----- + +* [1] https://developer.arm.com/documentation/den0118/a/ - FWU Specification +* [2] https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf - Dependable Boot Specification
doc/develop/uefi/index.rst +1 -0
@@ -13,3 +13,4 @@ can be run an UEFI payload. uefi.rst u-boot_on_efi.rst iscsi.rst + fwu_updates.rst
doc/develop/uefi/uefi.rst +2 -0
@@ -277,6 +277,8 @@ Enable ``CONFIG_OPTEE``, ``CONFIG_CMD_OPTEE_RPMB`` and ``CONFIG_EFI_MM_COMM_TEE` [1] https://optee.readthedocs.io/en/latest/building/efi_vars/stmm.html +.. _uefi_capsule_update_ref: + Enabling UEFI Capsule Update feature ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.34.1
Re: [PATCH v7 13/13] FWU: doc: Add documentation for the FWU feature
Quoted 20 lines · Sughosh Ganu
Add documentattion for the FWU Multi Bank Update feature. The document describes the steps needed for setting up the platform for the feature, as well as steps for enabling the feature on the platform.
Signed-off-by Sughosh Ganu <[email protected]>---
Changes since V6: Nonedoc/develop/uefi/fwu_updates.rst | 156 +++++++++++++++++++++++++++++++ doc/develop/uefi/index.rst | 1 + doc/develop/uefi/uefi.rst | 2 + 3 files changed, 159 insertions(+)create mode 100644
doc/develop/uefi/fwu_updates.rstdoc/develop/uefi/fwu_updates.rst new file +0
-0
doc/develop/uefi/fwu_updates.rst line 9
Quoted 9 lines
doc/develop/uefi/fwu_updates.rst new file +9
-0@@ -0,0 +1,156 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright (c) 2022 Linaro Limited + +FWU Multi Bank Updates in U-Boot +================================ + +The FWU Multi Bank Update feature implements the firmware update +mechanism described in the PSA Firmware Update for A-profile Arm +Architecture specification[1]. Certain aspects of the Dependable
Thanks a lot for the extensive documentation.
%s/\[1\]/ [1]/
doc/develop/uefi/fwu_updates.rst line 10
Quoted 1 line
doc/develop/uefi/fwu_updates.rst new file +1
-0+Boot specification[2] are also implemented. The feature provides a
ditto
Quoted 32 lines
doc/develop/uefi/fwu_updates.rst new file +32
-0+mechanism to have multiple banks of updatable firmware images and for +updating the firmware images on the non-booted bank. On a successful +update, the platform boots from the updated bank on subsequent +boot. The UEFI capsule-on-disk update feature is used for performing +the actual updates of the updatable firmware images. + +The bookkeeping of the updatable images is done through a structure +called metadata. Currently, the FWU metadata supports identification +of images based on image GUIDs stored on a GPT partitioned storage +media. There are plans to extend the metadata structure for non GPT +partitioned devices as well. + +Accessing the FWU metadata is done through generic API's which are +defined in a driver which complies with the u-boot's driver model. A +new uclass UCLASS_FWU_MDATA has been added for accessing the FWU +metadata. Individual drivers can be added based on the type of storage +media, and it's partitioning method. Details of the storage device +containing the FWU metadata partitions are specified through a U-Boot +specific device tree property `fwu-mdata-store`. Please refer to +U-Boot `doc <doc/device-tree-bindings/firmware/fwu-mdata.txt>`__ for +the device tree bindings. + +Enabling the FWU Multi Bank Update feature +------------------------------------------ + +The feature can be enabled by specifying the following configs:: + + CONFIG_EFI_CAPSULE_ON_DISK=y + CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT=y + CONFIG_EFI_CAPSULE_FIRMWARE=y + CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y +
doc/develop/uefi/fwu_updates.rst line 52
Quoted 10 lines
doc/develop/uefi/fwu_updates.rst new file +10
-0+ CONFIG_FWU_MULTI_BANK_UPDATE=y + CONFIG_CMD_FWU_METADATA=y + CONFIG_DM_FWU_MDATA=y + CONFIG_FWU_MDATA_GPT_BLK=y + CONFIG_FWU_NUM_BANKS=<val> + CONFIG_FWU_NUM_IMAGES_PER_BANK=<val> + +in the .config file + +The first group of configs enable the UEFI capsule-on-disk update
%s/configs/configuration settings/
doc/develop/uefi/fwu_updates.rst line 62
Quoted 10 lines
doc/develop/uefi/fwu_updates.rst new file +10
-0+functionality. The second group of configs enable the FWU Multi Bank +Update functionality. Please refer to the section +:ref:`uefi_capsule_update_ref` for more details on generation of the +UEFI capsule. + +Setting up the device for GPT partitioned storage +------------------------------------------------- + +Before enabling the functionality in U-Boot, certain changes are +required to be done on the storage device. Assuming a GPT partitioned
A GPT partitioned storage device is required.
doc/develop/uefi/fwu_updates.rst line 71
Quoted 9 lines
doc/develop/uefi/fwu_updates.rst new file +9
-0+storage device, the storage media needs to be partitioned with the +correct number of partitions, given the number of banks and number of +images per bank that the platform is going to support. Each updatable +firmware image will be stored on an separate partition. In addition, +the two copies of the FWU metadata will be stored on two separate +partitions. + +As an example, a platform supporting two banks with each bank +containing three images would need to have 2 * 3 = 6 parititions plus
%s/parititions/partitions/
Please, provide an example:
* meta data 1
* U-Boot 1
* ESP 1
* Operating system image 1
* meta data 2
* U-Boot 2
* ESP 2
* Operating system image 2
doc/develop/uefi/fwu_updates.rst line 74
Quoted 3 lines
doc/develop/uefi/fwu_updates.rst new file +3
-0+the two metadata partitions, or 8 partitions. In addition the storage +media can have additional partitions of non-updatable images, like the +EFI System Partition(ESP), a partition for the root file system etc.
Couldn't the ESP and the root file system also be updated by FWU for instance to switch to a new GRUB version or a new kernel?
doc/develop/uefi/fwu_updates.rst line 80
Quoted 6 lines
doc/develop/uefi/fwu_updates.rst new file +6
-0+ +When generating the partitions, a few aspects need to be taken care +of. Each GPT partition entry in the GPT header has two GUIDs:: + + *PartitionTypeGUID* + *UniquePartitionGUID*
Please, use a bullet list here.
doc/develop/uefi/fwu_updates.rst line 82
Quoted 2 lines
doc/develop/uefi/fwu_updates.rst new file +2
-0+ +The PartitionTypeGUID value should correspond to the *image_type_uuid*
You could use double backquotes to show variable names as code.
E.g. this is a ``variable``.
doc/develop/uefi/fwu_updates.rst line 84
Quoted 2 lines
doc/develop/uefi/fwu_updates.rst new file +2
-0+field of the FWU metadata. This field is used to identify a given type +of updatable firmware image, e.g. u-boot, op-tee, FIP etc. This GUID
%s/u-boot/U-Boot/
$s/op-tee/OP-TEE/
Best regards
Heinrich
Quoted 94 lines
doc/develop/uefi/fwu_updates.rst new file +72
-0+should also be used for specifying the `--guid` parameter when +generating the capsule. + +The UniquePartitionGUID value should correspond to the *image_uuid* +field in the FWU metadata. This GUID is used to identify images of a +given image type in different banks. + +Similarly, the FWU specifications defines the GUID value to be used +for the metadata partitions. This would be the PartitionTypeGUID for +the metadata partitions. + +When generating the metadata, the *image_type_uuid* and the +*image_uuid* values should match the *PartitionTypeGUID* and the +*UniquePartitionGUID* values respectively. + +Performing the Update +--------------------- + +Once the storage media has been partitioned and populated with the +metadata partitions, the UEFI capsule-on-disk update functionality can +be used for performing the update. Refer to the section +:ref:`uefi_capsule_update_ref` for details on how the update can be +invoked. + +On a successful update, the FWU metadata gets updated to reflect the +bank from which the platform would be booting on subsequent boot. + +Based on the value of bit15 of the Flags member of the capsule header, +the updated images would either be accepted by the u-boot's UEFI +implementation, or by the Operating System. If the Operating System is +accepting the firmware images, it does so by generating an empty +*accept* capsule. The Operating System can also reject the updated +firmware by generating a *revert* capsule. The empty capsule can be +applied by using the exact same procedure used for performing the +capsule-on-disk update. + +The task of accepting the different firmware images, post an update +may be done by multiple, separate components in the Operating +System. To help identify the firmware image that is being accepted, +the accept capsule passes the image GUID of the firmware image being +accepted. The relevant code in u-boot then sets the Accept bit of the +corresponding firmware image for which the accept capsule was +found. Only when all the firmware components in a bank have been +accepted does the platform transition to the regular state from trial +state. + +The revert capsule on the other hand does not pass any image GUID, +since reverting any image of the bank has the same result of the +platform booting from the other bank on subsequent boot. + +Generating an empty capsule +--------------------------- + +The empty capsule can be generated using the mkeficapsule utility. To +build the tool, enable:: + + CONFIG_TOOLS_MKEFICAPSULE=y + +Run the following commands to generate the accept/revert capsules:: + +.. code-block:: bash + + $ ./tools/mkeficapsule \ + [--fw-accept --guid <image guid>] | \ + [--fw-revert] \ + <capsule_file_name> + +Links +----- + +* [1] https://developer.arm.com/documentation/den0118/a/ - FWU Specification +* [2] https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf - Dependable Boot Specificationdoc/develop/uefi/index.rst +1
-0@@ -13,3 +13,4 @@ can be run an UEFI payload. uefi.rst u-boot_on_efi.rst iscsi.rst + fwu_updates.rstdoc/develop/uefi/uefi.rst +2
-0@@ -277,6 +277,8 @@ Enable ``CONFIG_OPTEE``, ``CONFIG_CMD_OPTEE_RPMB`` and ``CONFIG_EFI_MM_COMM_TEE` [1] https://optee.readthedocs.io/en/latest/building/efi_vars/stmm.html +.. _uefi_capsule_update_ref: + Enabling UEFI Capsule Update feature ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cover FWU: Add support for mtd backed feature on DeveloperBox
In reply to Sughosh GanuFrom: Jassi Brar <[email protected]>
The mtd and synquacer (developerbox) support was dropped from v6[1] This patchset re-introduces the support over last v7[2] submission of the patchset.
All the comments on this code over v5 submission have been addressed. Moving forward a changelog will be maintained.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Jassi Brar (2):
dt: fwu: developerbox: enable fwu banks and mdata regions
fwu: DeveloperBox: add support for FWU
Sughosh Ganu (3):
dt/bindings: Add bindings for FWU Metadata mtd storage
FWU: Add FWU metadata access driver for MTD storage regions
FWU: mtd: Add helper functions for accessing FWU metadata
.../synquacer-sc2a11-developerbox-u-boot.dtsi | 22 +- board/socionext/developerbox/Makefile | 1 + board/socionext/developerbox/developerbox.c | 13 + board/socionext/developerbox/fwu_plat.c | 95 ++++++ configs/synquacer_developerbox_defconfig | 13 +- doc/board/socionext/developerbox.rst | 96 ++++++ .../firmware/fwu-mdata-mtd.yaml | 38 +++ drivers/fwu-mdata/Kconfig | 8 + drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++++++++++++++++++ include/configs/synquacer.h | 10 + lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 173 ++++++++++ 13 files changed, 776 insertions(+), 3 deletions(-) create mode 100644 board/socionext/developerbox/fwu_plat.c create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml create mode 100644 drivers/fwu-mdata/fwu_mdata_mtd.c create mode 100644 lib/fwu_updates/fwu_mtd.c
Signature · 1 line
2.25.1
cover FWU: Add support for mtd backed feature on DeveloperBox
From: Jassi Brar <[email protected]>
The mtd and synquacer (developerbox) support was dropped from v6[1] This patchset re-introduces the support over last v7[2] submission of the patchset.
All the comments on this code over v5 submission have been addressed. Moving forward a changelog will be maintained.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Jassi Brar (2):
dt: fwu: developerbox: enable fwu banks and mdata regions
fwu: DeveloperBox: add support for FWU
Sughosh Ganu (3):
dt/bindings: Add bindings for FWU Metadata mtd storage
FWU: Add FWU metadata access driver for MTD storage regions
FWU: mtd: Add helper functions for accessing FWU metadata
.../synquacer-sc2a11-developerbox-u-boot.dtsi | 22 +- board/socionext/developerbox/Makefile | 1 + board/socionext/developerbox/developerbox.c | 13 + board/socionext/developerbox/fwu_plat.c | 95 ++++++ configs/synquacer_developerbox_defconfig | 13 +- doc/board/socionext/developerbox.rst | 96 ++++++ .../firmware/fwu-mdata-mtd.yaml | 38 +++ drivers/fwu-mdata/Kconfig | 8 + drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++++++++++++++++++ include/configs/synquacer.h | 10 + lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 173 ++++++++++ 13 files changed, 776 insertions(+), 3 deletions(-) create mode 100644 board/socionext/developerbox/fwu_plat.c create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml create mode 100644 drivers/fwu-mdata/fwu_mdata_mtd.c create mode 100644 lib/fwu_updates/fwu_mtd.c
Signature · 1 line
2.25.1
PATCH 1/5 dt/bindings: Add bindings for FWU Metadata mtd storage
From: Sughosh Ganu <[email protected]>
Add bindings needed for accessing the FWU metadata regions. These include the compatible string which point to the access method, the actual device which stores the FWU metadata and the offsets for both metadata regions.
The current patch adds basic bindings needed for accessing the metadata structure on non-GPT mtd regions.
--- .../firmware/fwu-mdata-mtd.yaml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml
doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml new file +38 -0
@@ -0,0 +1,38 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/firmware/u-boot,fwu-mdata-sf.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: FWU metadata on MTD device without GPT + +maintainers: + - Masami Hiramatsu <[email protected]> + +properties: + compatible: + items: + - const: u-boot,fwu-mdata-mtd + + fwu-mdata-store: + maxItems: 1 + description: Phandle of the MTD device which contains the FWU medatata. + + mdata-offsets: + minItems: 2 + description: Offsets of the primary and secondary FWU metadata in the NOR flash. + +required: + - compatible + - fwu-mdata-store + - mdata-offsets + +additionalProperties: false + +examples: + - | + fwu-mdata { + compatible = "u-boot,fwu-mdata-mtd"; + fwu-mdata-store = <&spi-flash>; + mdata-offsets = <0x500000 0x530000>; + };
Signature · 1 line
2.25.1
Re: [PATCH 1/5] dt/bindings: Add bindings for FWU Metadata mtd storage
Quoted 8 lines · On Fri, 22 Jul 2022 at 23:13, <[email protected]> wrote:
From: Sughosh Ganu <[email protected]>
Add bindings needed for accessing the FWU metadata regions. These include the compatible string which point to the access method, the actual device which stores the FWU metadata and the offsets for both metadata regions.
Quoted 5 lines
The current patch adds basic bindings needed for accessing the metadata structure on non-GPT mtd regions.
Signed-off-by Masami Hiramatsu <[email protected]>Signed-off-by Jassi Brar <[email protected]>
This patch is authored by Masami Hiramatsu, and should reflect that.
-sughosh
Quoted 52 lines
--- .../firmware/fwu-mdata-mtd.yaml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-mtd.yamldoc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml new file +38
-1@@ -0,0 +1,38 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/firmware/u-boot,fwu-mdata-sf.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: FWU metadata on MTD device without GPT + +maintainers: + - Masami Hiramatsu <[email protected]> + +properties: + compatible: + items: + - const: u-boot,fwu-mdata-mtd + + fwu-mdata-store: + maxItems: 1 + description: Phandle of the MTD device which contains the FWU medatata. + + mdata-offsets: + minItems: 2 + description: Offsets of the primary and secondary FWU metadata in the NOR flash. + +required: + - compatible + - fwu-mdata-store + - mdata-offsets + +additionalProperties: false + +examples: + - | + fwu-mdata { + compatible = "u-boot,fwu-mdata-mtd"; + fwu-mdata-store = <&spi-flash>; + mdata-offsets = <0x500000 0x530000>; + }; --2.25.1
PATCH 2/5 FWU: Add FWU metadata access driver for MTD storage regions
In reply to [email protected]From: Sughosh Ganu <[email protected]>
In the FWU Multi Bank Update feature, the information about the updatable images is stored as part of the metadata, on a separate region. Add a driver for reading from and writing to the metadata when the updatable images and the metadata are stored on a raw MTD region.
--- drivers/fwu-mdata/Kconfig | 8 + drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++++++++++++++++++++++++++++++ 3 files changed, 317 insertions(+) create mode 100644 drivers/fwu-mdata/fwu_mdata_mtd.c
drivers/fwu-mdata/Kconfig +8 -0
@@ -14,3 +14,11 @@ config FWU_MDATA_GPT_BLK help Enable support for accessing FWU Metadata on GPT partitioned block devices. + +config FWU_MDATA_MTD + bool "FWU Metadata access for non-GPT MTD devices" + depends on DM_FWU_MDATA && MTD + help + Enable support for accessing FWU Metadata on non-partitioned + (or non-GPT partitioned, e.g. partition nodes in devicetree) + MTD devices.
drivers/fwu-mdata/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata_gpt_blk.o +obj-$(CONFIG_FWU_MDATA_MTD) += fwu_mdata_mtd.o
drivers/fwu-mdata/fwu_mdata_mtd.c new file +308 -0
308 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH 2/5] FWU: Add FWU metadata access driver for MTD storage regions
Quoted 56 lines · On 7/22/22 19:43, [email protected] wrote:
From: Sughosh Ganu <[email protected]>
In the FWU Multi Bank Update feature, the information about the updatable images is stored as part of the metadata, on a separate region. Add a driver for reading from and writing to the metadata when the updatable images and the metadata are stored on a raw MTD region.
Signed-off-by Sughosh Ganu <[email protected]>Signed-off-by Jassi Brar <[email protected]>--- drivers/fwu-mdata/Kconfig | 8 + drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++++++++++++++++++++++++++++++ 3 files changed, 317 insertions(+)create mode 100644
drivers/fwu-mdata/fwu_mdata_mtd.cdrivers/fwu-mdata/Kconfig +8
-0@@ -14,3 +14,11 @@ config FWU_MDATA_GPT_BLK help Enable support for accessing FWU Metadata on GPT partitioned block devices. + +config FWU_MDATA_MTD + bool "FWU Metadata access for non-GPT MTD devices" + depends on DM_FWU_MDATA && MTD + help + Enable support for accessing FWU Metadata on non-partitioned + (or non-GPT partitioned, e.g. partition nodes in devicetree) + MTD devices.drivers/fwu-mdata/Makefile +1
-0@@ -5,3 +5,4 @@ obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata_gpt_blk.o +obj-$(CONFIG_FWU_MDATA_MTD) += fwu_mdata_mtd.odrivers/fwu-mdata/fwu_mdata_mtd.c new file +8
-0@@ -0,0 +1,308 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022, Linaro Limited +*/ + +#include <efi_loader.h> +#include <fwu.h> +#include <fwu_mdata.h>
drivers/fwu-mdata/fwu_mdata_mtd.c line 18
Quoted 10 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +10
-0+#include <malloc.h> +#include <memalign.h> +#include <spi.h> +#include <spi_flash.h> +#include <flash.h> + +#include <linux/errno.h> +#include <linux/types.h> +#include <u-boot/crc.h> +
How should a reader know what pri_offset and sec_offset refer to? Please, provide Sphix style comments describing the structure.
drivers/fwu-mdata/fwu_mdata_mtd.c line 29
Quoted 11 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +11
-0+struct fwu_mdata_mtd_priv { +struct mtd_info *mtd; +u32 pri_offset; +u32 sec_offset; +}; + +enum fwu_mtd_op { +FWU_MTD_READ , +FWU_MTD_WRITE , +}; +
Please, document all functions.
drivers/fwu-mdata/fwu_mdata_mtd.c line 36
Quoted 7 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +7
-0+static bool /(struct mtd_info *mtd, u64 size) +{ + return !do_div(size, mtd->erasesize); +} + +static int mtd_io_data (struct mtd_info *mtd,u32 offs,u32 size,void *data, +enum fwu_mtd_op op)
Most of the functionality of this function should be in the mtd uclass. It is not FWU specific.
drivers/fwu-mdata/fwu_mdata_mtd.c line 45
Quoted 9 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +9
-0+{ +struct mtd_oob_ops io_op ={}; +u64 lock_offs, lock_len; +size_t len; +void *buf; +int ret; + +if (!mtd_is_aligned_with_block_size (mtd, offs)) +return -EINVAL ;
I think this is the only place where you could write an error message indicating that misplacement is the reason for the error.
drivers/fwu-mdata/fwu_mdata_mtd.c line 56
Quoted 11 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +11
-0+ lock_offs = offs; + lock_len =round_up (size, mtd->erasesize); + + ret =mtd_unlock (mtd, lock_offs, lock_len); +if (ret && ret != -EOPNOTSUPP ) +return ret; + +if (op ==FWU_MTD_WRITE ) { +struct erase_info erase_op = {}; + +/* This will expand erase size to align with the block size */
This comment is misplaced. It should be above the round_up() call.
Quoted 16 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +16
-0+ erase_op.mtd = mtd; + erase_op.addr = lock_offs; + erase_op.len = lock_len; + erase_op.scrub =0 ; + + ret =mtd_erase (mtd, &erase_op); +if (ret) + goto lock_out; + } + +/* Also, expand the write size to align with the write size */ + len =round_up (size, mtd->writesize); + + buf =memalign (ARCH_DMA_MINALIGN , len); +if (!buf) { + ret = -ENOMEM ;
drivers/fwu-mdata/fwu_mdata_mtd.c line 82
Quoted 10 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +10
-0+ goto lock_out; + } + io_op.mode =MTD_OPS_AUTO_OOB ; + io_op.len = len; + io_op.ooblen =0 ; + io_op.datbuf = buf; + io_op.oobbuf =NULL ; + +if (op ==FWU_MTD_WRITE ) { +memcpy (buf, data, size);
Don't copy random bytes to the flash. You have to zero out the padding bytes.
drivers/fwu-mdata/fwu_mdata_mtd.c line 91
Quoted 9 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +9
-0+ ret =mtd_write_oob (mtd, offs, &io_op); + }else { + ret =mtd_read_oob (mtd, offs, &io_op); +if (!ret) +memcpy (data, buf, size); + } +free (buf); + +lock_out:
This label sound like you want to lock something out. Please use lock:
instead.
Quoted 6 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +6
-0+mtd_lock (mtd, lock_offs, lock_len); + +return ret; +} + +static int fwu_mtd_load_mdata(struct mtd_info *mtd, struct fwu_mdata **mdata,
drivers/fwu-mdata/fwu_mdata_mtd.c line 107
Quoted 10 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +10
-0+ u32 offs, bool primary) +{ + size_t size = sizeof(struct fwu_mdata); +int ret; + + *mdata =malloc (size); +if (!*mdata) +return -ENOMEM ; + + ret =mtd_io_data (mtd, offs, size, (void *)*mdata,FWU_MTD_READ );
The conversion to (void *) is superfluous as the expected parameter is of type void *.
Quoted 5 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +5
-0+if (ret >=0 ) { + ret =fwu_verify_mdata (*mdata, primary); +if (ret <0 ) { +free (*mdata); + *mdata =NULL ;
drivers/fwu-mdata/fwu_mdata_mtd.c line 122
Quoted 10 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +10
-0+ } + } + +return ret; +} + +static int fwu_mtd_load_primary_mdata (struct fwu_mdata_mtd_priv *mtd_priv, +struct fwu_mdata **mdata) +{ +return fwu_mtd_load_mdata (mtd_priv->mtd, mdata, mtd_priv->pri_offset, true);
Instead of true and false use an enum like
enum fwu_sec_prim {
FWU_META_PRIMARY,
FWU_META_SECONDARY,
}
and get rid of these functions. That will give you the same readability with less of complexity.
Quoted 16 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +16
-0+} + +static int fwu_mtd_load_secondary_mdata (struct fwu_mdata_mtd_priv *mtd_priv, +struct fwu_mdata **mdata) +{ +return fwu_mtd_load_mdata (mtd_priv->mtd, mdata, mtd_priv->sec_offset, false); +} + +static int fwu_mtd_save_primary_mdata (struct fwu_mdata_mtd_priv *mtd_priv, +struct fwu_mdata *mdata) +{ +return mtd_io_data (mtd_priv->mtd, mtd_priv->pri_offset, +sizeof (struct fwu_mdata ), mdata,FWU_MTD_WRITE ); +} + +static int fwu_mtd_save_secondary_mdata(struct fwu_mdata_mtd_priv *mtd_priv,
drivers/fwu-mdata/fwu_mdata_mtd.c line 148
Quoted 10 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +10
-0+ struct fwu_mdata *mdata) +{ +return mtd_io_data (mtd_priv->mtd, mtd_priv->sec_offset, +sizeof (struct fwu_mdata ), mdata,FWU_MTD_WRITE ); +} + +static int fwu_mtd_get_valid_mdata (struct fwu_mdata_mtd_priv *mtd_priv, +struct fwu_mdata **mdata) +{ +if (fwu_mtd_load_primary_mdata (mtd_priv, mdata) ==0 )
Please, don't use == 0. But "if (!".
drivers/fwu-mdata/fwu_mdata_mtd.c line 153
Quoted 5 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +5
-0+return 0 ; + +log_err ("Failed to load/verify primary mdata. Try secondary.\n" ); + +if (fwu_mtd_load_secondary_mdata (mtd_priv, mdata) ==0 )
ditto
Quoted 4 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +4
-0+return 0 ; + +log_err ("Failed to load/verify secondary mdata.\n" ); +
drivers/fwu-mdata/fwu_mdata_mtd.c line 167
Quoted 10 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +10
-0+return -1 ; +} + +static int fwu_mtd_update_mdata (struct udevice *dev,struct fwu_mdata *mdata) +{ +struct fwu_mdata_mtd_priv *mtd_priv =dev_get_priv (dev); +int ret; + +/* Update mdata crc32 field */ + mdata->crc32 = crc32(0, (void *)&mdata->version,
Avoid superfluous conversions. There is already a conversion in the defintion of the crc32 macro.
Quoted 37 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +37
-0+ sizeof(*mdata) - sizeof(u32)); + +/* First write the primary mdata */ + ret =fwu_mtd_save_primary_mdata (mtd_priv, mdata); +if (ret <0 ) { +log_err ("Failed to update the primary mdata.\n" ); +return ret; + } + +/* And now the replica */ + ret =fwu_mtd_save_secondary_mdata (mtd_priv, mdata); +if (ret <0 ) { +log_err ("Failed to update the secondary mdata.\n" ); +return ret; + } + +return 0 ; +} + +static int fwu_mtd_mdata_check (struct udevice *dev) +{ +struct fwu_mdata *primary =NULL , *secondary =NULL ; +struct fwu_mdata_mtd_priv *mtd_priv =dev_get_priv (dev); +int ret; + + ret =fwu_mtd_load_primary_mdata (mtd_priv, &primary); +if (ret <0 ) +log_err ("Failed to read the primary mdata: %d\n" , ret); + + ret =fwu_mtd_load_secondary_mdata (mtd_priv, &secondary); +if (ret <0 ) +log_err ("Failed to read the secondary mdata: %d\n" , ret); + +if (primary && secondary) { +if (memcmp (primary, secondary,sizeof (struct fwu_mdata ))) { +log_err ("The primary and the secondary mdata are different\n" ); + ret =-1 ;
drivers/fwu-mdata/fwu_mdata_mtd.c line 214
Quoted 10 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +10
-0+ } + }else if (primary) { + ret =fwu_mtd_save_secondary_mdata (mtd_priv, primary); +if (ret <0 ) +log_err ("Restoring secondary mdata partition failed\n" ); + }else if (secondary) { + ret =fwu_mtd_save_primary_mdata (mtd_priv, secondary); +if (ret <0 ) +log_err ("Restoring primary mdata partition failed\n" ); + }
If neither primary nor secondary data is available, you are happy???
Quoted 20 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +20
-0+ +free (primary); +free (secondary); +return ret; +} + +static int fwu_mtd_get_mdata (struct udevice *dev,struct fwu_mdata **mdata) +{ +struct fwu_mdata_mtd_priv *mtd_priv =dev_get_priv (dev); + +return fwu_mtd_get_valid_mdata (mtd_priv, mdata); +} + +/** +* fwu_mdata_mtd_of_to_plat() - Translate from DT to fwu mdata device +*/ +static int fwu_mdata_mtd_of_to_plat (struct udevice *dev) +{ +struct fwu_mdata_mtd_priv *mtd_priv =dev_get_priv (dev); +const fdt32_t *phandle_p =NULL ;
drivers/fwu-mdata/fwu_mdata_mtd.c line 244
Quoted 10 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +10
-0+struct udevice *mtd_dev; +struct mtd_info *mtd; +int ret, size; +u32 phandle; + +/* Find the FWU mdata storage device */ + phandle_p =ofnode_get_property (dev_ofnode (dev), +"fwu-mdata-store" , &size); +if (!phandle_p) { +log_err ("fwu-mdata-store property not found\n" );
A user needs to know that the problem is in the device-tree, e.g. "FWU meta data store not defined in device-tree".
drivers/fwu-mdata/fwu_mdata_mtd.c line 254
Quoted 10 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +10
-0+return -ENOENT ; + } + + phandle =fdt32_to_cpu (*phandle_p); + + ret =device_get_global_by_ofnode ( +ofnode_get_by_phandle (phandle), + &mtd_dev); +if (ret) +return ret;
No log message?
Quoted 22 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +22
-0+ +mtd_probe_devices (); + +mtd_for_each_device (mtd) { +if (mtd->dev == mtd_dev) { + mtd_priv->mtd = mtd; +log_debug ("Found the FWU mdata mtd device %s\n" , mtd->name); +break ; + } + } +if (!mtd_priv->mtd) { +log_err ("Failed to find mtd device by fwu-mdata-store\n" ); +return -ENOENT ; + } + +/* Get the offset of primary and seconday mdata */ + ret =ofnode_read_u32_index (dev_ofnode (dev),"mdata-offsets" ,0 , + &mtd_priv->pri_offset); +if (ret) +return ret; + ret =ofnode_read_u32_index (dev_ofnode (dev),"mdata-offsets" ,1 , + &mtd_priv->sec_offset);
drivers/fwu-mdata/fwu_mdata_mtd.c line 286
Quoted 10 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +10
-0+if (ret) +return ret; + +return 0 ; +} + +static int fwu_mdata_mtd_probe (struct udevice *dev) +{ +/* Ensure the metadata can be read. */ +return fwu_mtd_mdata_check (dev);
If you don't like the name of fwu_mtd_mdata_check(), change it instead of wrapping it in another function.
Best regards
Heinrich
Quoted 22 lines
drivers/fwu-mdata/fwu_mdata_mtd.c new file +22
-0+} + +static struct fwu_mdata_ops fwu_mtd_ops = { + .mdata_check = fwu_mtd_mdata_check, + .get_mdata = fwu_mtd_get_mdata, + .update_mdata = fwu_mtd_update_mdata, +}; + +static const struct udevice_id fwu_mdata_ids[] = { + { .compatible ="u-boot,fwu-mdata-mtd" }, + { } +}; + +U_BOOT_DRIVER (fwu_mdata_mtd) = { + .name ="fwu-mdata-mtd" , + .id =UCLASS_FWU_MDATA , + .of_match = fwu_mdata_ids, + .ops = &fwu_mtd_ops, + .probe = fwu_mdata_mtd_probe, + .of_to_plat = fwu_mdata_mtd_of_to_plat, + .priv_auto =sizeof (struct fwu_mdata_mtd_priv ), +};
PATCH 3/5 FWU: mtd: Add helper functions for accessing FWU metadata
In reply to [email protected]From: Sughosh Ganu <[email protected]>
Add helper functions needed for accessing the FWU metadata which contains information on the updatable images.
--- lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 173 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 lib/fwu_updates/fwu_mtd.c
lib/fwu_updates/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu.o obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_gpt.o +obj-$(CONFIG_FWU_MDATA_MTD) += fwu_mtd.o
lib/fwu_updates/fwu_mtd.c new file +173 -0
173 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH 3/5] FWU: mtd: Add helper functions for accessing FWU metadata
Quoted 34 lines · On 7/22/22 19:43, [email protected] wrote:
From: Sughosh Ganu <[email protected]>
Add helper functions needed for accessing the FWU metadata which contains information on the updatable images.
Signed-off-by Sughosh Ganu <[email protected]>Signed-off-by Jassi Brar <[email protected]>--- lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 173 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+)create mode 100644
lib/fwu_updates/fwu_mtd.clib/fwu_updates/Makefile +1
-0@@ -5,3 +5,4 @@ obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu.o obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_gpt.o +obj-$(CONFIG_FWU_MDATA_MTD) += fwu_mtd.olib/fwu_updates/fwu_mtd.c new file +6
-0@@ -0,0 +1,173 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022, Linaro Limited +*/ + +#include <dfu.h>
lib/fwu_updates/fwu_mtd.c line 16
Quoted 10 lines
lib/fwu_updates/fwu_mtd.c new file +10
-0+#include <fwu.h> +#include <fwu_mdata.h> +#include <log.h> +#include <malloc.h> +#include <mtd.h> +#include <uuid.h> +#include <vsprintf.h> + +#include <dm/ofnode.h> +
Please, document functions.
You missed adding the function to an include in the series. The include changes should be in the same patch as the library functions.
Quoted 16 lines
lib/fwu_updates/fwu_mtd.c new file +16
-0+int mtd_plat_get_alt_num (efi_guid_t *image_id,int *alt_num, +const char *mtd_dev,bool guid) +{ +int i, nalt; +int ret =-1 ; +struct mtd_info *mtd; +struct dfu_entity *dfu; +ofnode node, parts_node; +fdt_addr_t offset, size; +char uuidbuf[UUID_STR_LEN +1 ]; + +mtd_probe_devices (); + mtd =get_mtd_device_nm (mtd_dev); + +/* Find partition node under given MTD device. */ + parts_node = ofnode_by_compatible(mtd_get_ofnode(mtd),
lib/fwu_updates/fwu_mtd.c line 42
Quoted 10 lines
lib/fwu_updates/fwu_mtd.c new file +10
-0+ "fixed-partitions"); + +uuid_bin_to_str (image_id->b, uuidbuf, + guid ?UUID_STR_FORMAT_GUID :UUID_STR_FORMAT_STD ); + node =ofnode_by_prop_value (parts_node,"uuid" , uuidbuf, +sizeof (uuidbuf)); +if (!ofnode_valid (node)) { +log_warning ("Warning: Failed to find partition by image UUID\n" ); +return -ENOENT ; + }
Isn't finding an mtd partition by UUID something that should be a function in the mtd uclass because it may find usages outside FWU?
Quoted 58 lines
lib/fwu_updates/fwu_mtd.c new file +58
-0+ + offset =ofnode_get_addr_size_index_notrans (node,0 , &size); +if (offset ==FDT_ADDR_T_NONE || !size) +return -ENOENT ; + +dfu_init_env_entities (NULL ,NULL ); + + nalt =0 ; +list_for_each_entry (dfu, &dfu_list, list) { + nalt++; + } + +if (!nalt) { +log_warning ("No entities in dfu_alt_info\n" ); +dfu_free_entities (); +return -ENOENT ; + } + +for (i =0 ; i < nalt; i++) { + dfu =dfu_get_entity (i); + +if (!dfu) +continue ; + +if (dfu->dev_type !=DFU_DEV_MTD ) +continue ; + +if (dfu->layout ==DFU_RAW_ADDR && + dfu->data.mtd.start == offset && + dfu->data.mtd.size == size) { + *alt_num = dfu->alt; + ret =0 ; +break ; + } + } + +dfu_free_entities (); + +return ret; +} + +int gen_image_alt_info (char *buf,size_t len,int sidx, +struct fwu_image_entry *img,struct mtd_info *mtd) +{ +int i; +const char *suuid; +ofnode node, parts_node; +char uuidbuf[UUID_STR_LEN +1 ]; +char *p = buf, *end = buf + len; + +/* Find partition node under given MTD device. */ + parts_node =ofnode_by_compatible (mtd_get_ofnode (mtd), +"fixed-partitions" ); +if (!ofnode_valid (parts_node)) +return -ENOENT ; + +/* Check the media UUID if exist. */ + suuid =ofnode_read_string (parts_node,"uuid" );
lib/fwu_updates/fwu_mtd.c line 110
Quoted 10 lines
lib/fwu_updates/fwu_mtd.c new file +10
-0+if (suuid) { +log_debug ("Get location uuid %s\n" , suuid); +uuid_bin_to_str (img->location_uuid.b, uuidbuf, +UUID_STR_FORMAT_STD ); +if (strcasecmp (suuid, uuidbuf)) +log_warning ("Warning: Location UUID does not match!\n" ); + } + + p +=snprintf (p, end - p,"mtd %s" , mtd->name); +if (end < p)
err_log() needed?
lib/fwu_updates/fwu_mtd.c line 114
Quoted 4 lines
lib/fwu_updates/fwu_mtd.c new file +4
-0+return -E2BIG ; + +/* +* List up the image banks in the FWU mdata and search the corresponding
%s/up //
Quoted 19 lines
lib/fwu_updates/fwu_mtd.c new file +19
-0+* partition based on partition's uuid. +*/ +for (i =0 ; i <CONFIG_FWU_NUM_BANKS ; i++) { +struct fwu_image_bank_info *bank; +fdt_addr_t offset, size; + +/* Query a partition by image UUID */ + bank = &img->img_bank_info[i]; +uuid_bin_to_str (bank->image_uuid.b, uuidbuf, +UUID_STR_FORMAT_STD ); + node =ofnode_by_prop_value (parts_node,"uuid" , uuidbuf, +sizeof (uuidbuf)); +if (!ofnode_valid (node)) { +log_warning ("Warning: Failed to find partition by image UUID\n" ); +break ; + } + + offset =ofnode_get_addr_size_index_notrans (node,0 , &size); +if (offset ==FDT_ADDR_T_NONE || !size)
lib/fwu_updates/fwu_mtd.c line 143
Quoted 10 lines
lib/fwu_updates/fwu_mtd.c new file +10
-0+break ; + + p +=snprintf (p, end - p,"%sbank%d raw %lx %lx" , + i ==0 ?"=" :";" , i, (unsigned long )offset, + (unsigned long )size); +if (end < p) +return -E2BIG ; + } + +return i !=CONFIG_FWU_NUM_BANKS ? -ENOENT :0 ;
This is easier to read:
if (i != CONFIG_FWU_NUM_BANKS)
return -ENOENT;
return 0;
Best regards
Heinrich
Quoted 30 lines
lib/fwu_updates/fwu_mtd.c new file +30
-0+} + +int fwu_gen_alt_info_from_mtd (char *buf,size_t len,struct mtd_info *mtd) +{ +struct fwu_mdata *mdata =NULL ; +int i, l, ret; + + ret =fwu_get_mdata (&mdata); +if (ret <0 ) { +log_debug ("Failed to get the FWU mdata.\n" ); +return ret; + } + +for (i =0 ; i <CONFIG_FWU_NUM_IMAGES_PER_BANK ; i++) { + ret =gen_image_alt_info (buf, len, i *CONFIG_FWU_NUM_BANKS , + &mdata->img_entry[i], mtd); +if (ret) +break ; + l =strlen (buf); +/* Replace the last ';' with '&' if there is another image. */ +if (i !=CONFIG_FWU_NUM_IMAGES_PER_BANK -1 && l) + buf[l -1 ] ='&' ; + len -= l; + buf += l; + } + +free (mdata); + +return ret; +}
PATCH 4/5 dt: fwu: developerbox: enable fwu banks and mdata regions
In reply to [email protected]From: Jassi Brar <[email protected]>
specify Bank-0/1 and fwu metadata mtd regions.
--- .../synquacer-sc2a11-developerbox-u-boot.dtsi | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi +21 -1
@@ -23,7 +23,7 @@ active_clk_edges; chipselect_num = <1>; - spi-flash@0 { + spi_flash: spi-flash@0 { #address-cells = <1>; #size-cells = <1>; compatible = "jedec,spi-nor";
@@ -36,6 +36,7 @@ compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; + uuid = "17e86d77-41f9-4fd7-87ec-a55df9842de5"; partition@0 { label = "BootStrap-BL1";
@@ -79,6 +80,19 @@ label = "Ex-OPTEE"; reg = <0x500000 0x200000>; }; + + /* FWU Multi bank update partitions */ + partition@600000 { + label = "FIP-Bank0"; + reg = <0x600000 0x400000>; + uuid = "5a66a702-99fd-4fef-a392-c26e261a2828"; + }; + + partition@a00000 { + label = "FIP-Bank1"; + reg = <0xa00000 0x400000>; + uuid = "a8f868a1-6e5c-4757-878d-ce63375ef2c0"; + }; }; }; };
@@ -104,6 +118,12 @@ optee { status = "okay"; }; + + fwu-mdata { + compatible = "u-boot,fwu-mdata-mtd"; + fwu-mdata-store = <&spi_flash>; + mdata-offsets = <0x500000 0x530000>; + }; }; };
Signature · 1 line
2.25.1
PATCH 5/5 fwu: DeveloperBox: add support for FWU
In reply to [email protected]From: Jassi Brar <[email protected]>
Add code to support FWU_MULTI_BANK_UPDATE. The platform does not have gpt-partition storage for Banks and MetaData, rather it used SPI-NOR backed mtd regions for the purpose.
--- board/socionext/developerbox/Makefile | 1 + board/socionext/developerbox/developerbox.c | 13 +++ board/socionext/developerbox/fwu_plat.c | 95 ++++++++++++++++++++ configs/synquacer_developerbox_defconfig | 13 ++- doc/board/socionext/developerbox.rst | 96 +++++++++++++++++++++ include/configs/synquacer.h | 10 +++ 6 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 board/socionext/developerbox/fwu_plat.c
board/socionext/developerbox/Makefile +1 -0
@@ -7,3 +7,4 @@ # obj-y := developerbox.o +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu_plat.o
board/socionext/developerbox/developerbox.c +13 -0
@@ -20,6 +20,13 @@ #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) struct efi_fw_image fw_images[] = { +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE) + { + .image_type_id = DEVELOPERBOX_FIP_IMAGE_GUID, + .fw_name = u"DEVELOPERBOX-FIP", + .image_index = 1, + }, +#else { .image_type_id = DEVELOPERBOX_UBOOT_IMAGE_GUID, .fw_name = u"DEVELOPERBOX-UBOOT",
@@ -35,12 +42,18 @@ struct efi_fw_image fw_images[] = { .fw_name = u"DEVELOPERBOX-OPTEE", .image_index = 3, }, +#endif }; struct efi_capsule_update_info update_info = { +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE ) + .dfu_string = "mtd nor1=bank0 raw 600000 400000;" + "bank1 raw a00000 400000;", +#else .dfu_string ="mtd nor1=u-boot.bin raw 200000 100000;" "fip.bin raw 180000 78000;" "optee.bin raw 500000 100000", +#endif .images = fw_images, };
board/socionext/developerbox/fwu_plat.c new file +95 -0
95 lines not on this page · raw message
configs/synquacer_developerbox_defconfig +11 -2
@@ -1,10 +1,11 @@ CONFIG_ARM=y CONFIG_ARCH_SYNQUACER=y -CONFIG_SYS_TEXT_BASE=0x08200000 +CONFIG_POSITION_INDEPENDENT=y +CONFIG_SYS_TEXT_BASE=0 CONFIG_SYS_MALLOC_LEN=0x1000000 CONFIG_SYS_MALLOC_F_LEN=0x400 CONFIG_ENV_SIZE=0x30000 -CONFIG_ENV_OFFSET=0x300000 +CONFIG_ENV_OFFSET=0x580000 CONFIG_ENV_SECT_SIZE=0x10000 CONFIG_DM_GPIO=y CONFIG_DEFAULT_DEVICE_TREE="synquacer-sc2a11-developerbox"
@@ -93,3 +94,11 @@ CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y CONFIG_EFI_CAPSULE_ON_DISK=y CONFIG_EFI_IGNORE_OSINDICATIONS=y CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y +CONFIG_EFI_SECURE_BOOT=y +CONFIG_BOARD_LATE_INIT=y +CONFIG_FWU_MULTI_BANK_UPDATE=y +CONFIG_DM_FWU_MDATA=y +CONFIG_FWU_MDATA_MTD=y +CONFIG_FWU_NUM_BANKS=2 +CONFIG_FWU_NUM_IMAGES_PER_BANK=1 +CONFIG_CMD_FWU_METADATA=y
doc/board/socionext/developerbox.rst +96 -0
99 lines not on this page · raw message
include/configs/synquacer.h +10 -0
@@ -46,19 +46,29 @@/* Since U-Boot 64bit PCIe support is limited, disable 64bit MMIO support */ +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEFAULT_DFU_ALT_INFO +#else #define DEFAULT_DFU_ALT_INFO "dfu_alt_info=" \ "mtd nor1=u-boot.bin raw 200000 100000;" \ "fip.bin raw 180000 78000;" \ "optee.bin raw 500000 100000\0" +#endif /* GUIDs for capsule updatable firmware images */ #define DEVELOPERBOX_UBOOT_IMAGE_GUID \ EFI_GUID(0x53a92e83, 0x4ef4, 0x473a, 0x8b, 0x0d, \ 0xb5, 0xd8, 0xc7, 0xb2, 0xd6, 0x00) +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEVELOPERBOX_FIP_IMAGE_GUID \ + EFI_GUID(0x7d6dc310, 0x52ca, 0x43b8, 0xb7, 0xb9, \ + 0xf9, 0xd6, 0xc5, 0x01, 0xd1, 0x08) +#else #define DEVELOPERBOX_FIP_IMAGE_GUID \ EFI_GUID(0x880866e9, 0x84ba, 0x4793, 0xa9, 0x08, \ 0x33, 0xe0, 0xb9, 0x16, 0xf3, 0x98) +#endif #define DEVELOPERBOX_OPTEE_IMAGE_GUID \ EFI_GUID(0xc1b629f1, 0xce0e, 0x4894, 0x82, 0xbf, \
Signature · 1 line
2.25.1
Re: [PATCH 5/5] fwu: DeveloperBox: add support for FWU
Quoted 33 lines · On 7/22/22 19:43, [email protected] wrote:
From: Jassi Brar <[email protected]>
Add code to support
FWU_MULTI_BANK_UPDATE. The platform does not have gpt-partition storage for Banks and MetaData, rather it used SPI-NOR backed mtd regions for the purpose.Signed-off-by Masami Hiramatsu <[email protected]>Signed-off-by Jassi Brar <[email protected]>--- board/socionext/developerbox/Makefile | 1 + board/socionext/developerbox/developerbox.c | 13 +++ board/socionext/developerbox/fwu_plat.c | 95 ++++++++++++++++++++ configs/synquacer_developerbox_defconfig | 13 ++- doc/board/socionext/developerbox.rst | 96 +++++++++++++++++++++ include/configs/synquacer.h | 10 +++ 6 files changed, 226 insertions(+), 2 deletions(-)create mode 100644
board/socionext/developerbox/fwu_plat.cboard/socionext/developerbox/Makefile +1
-0@@ -7,3 +7,4 @@ # obj-y := developerbox.o +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu_plat.oboard/socionext/developerbox/developerbox.c +0
-0
board/socionext/developerbox/developerbox.c line 26
Quoted 7 lines
board/socionext/developerbox/developerbox.c +4
-0@@ -20,6 +20,13 @@ #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) struct efi_fw_image fw_images[] = { +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE) + { + .image_type_id = DEVELOPERBOX_FIP_IMAGE_GUID, + .fw_name = u"DEVELOPERBOX-FIP",
The design is flawed. These fields should be moved to the device-tree.
Best regards
Heinrich
Quoted 294 lines
board/socionext/developerbox/developerbox.c +9
-0+ .image_index = 1, + }, +#else { .image_type_id = DEVELOPERBOX_UBOOT_IMAGE_GUID, .fw_name = u"DEVELOPERBOX-UBOOT",@@ -35,12 +42,18 @@ struct efi_fw_image fw_images[] = { .fw_name = u"DEVELOPERBOX-OPTEE", .image_index = 3, }, +#endif }; struct efi_capsule_update_info update_info = { +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE ) + .dfu_string = "mtd nor1=bank0 raw 600000 400000;" + "bank1 raw a00000 400000;", +#else .dfu_string ="mtd nor1=u-boot.bin raw 200000 100000;" "fip.bin raw 180000 78000;" "optee.bin raw 500000 100000", +#endif .images = fw_images, };board/socionext/developerbox/fwu_plat.c new file +95
-0@@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2021, Linaro Limited +*/ + +#include <dfu.h> +#include <efi_loader.h> +#include <flash.h> +#include <fwu.h> +#include <fwu_mdata.h> +#include <malloc.h> +#include <memalign.h> +#include <mtd.h> +#include <spi.h> +#include <spi_flash.h> +#include <uuid.h> + +#include <linux/errno.h> +#include <linux/types.h> +#include <u-boot/crc.h> + +#define DFU_ALT_BUF_LEN 256 +#define DFU_ALT_NUM_MAX (CONFIG_FWU_NUM_IMAGES_PER_BANK * CONFIG_FWU_NUM_BANKS) + +/* Generate dfu_alt_info from partitions */ +void set_dfu_alt_info (char *interface,char *devstr) +{ +int ret; +struct mtd_info *mtd; +static char *buf =NULL ; + +if (!buf) { + buf =malloc_cache_aligned (DFU_ALT_BUF_LEN ); +memset (buf,0 ,DFU_ALT_BUF_LEN ); + +mtd_probe_devices (); + + mtd =get_mtd_device_nm ("nor1" ); +if (IS_ERR_OR_NULL (mtd)) +return ; + + ret =fwu_gen_alt_info_from_mtd (buf,DFU_ALT_BUF_LEN , mtd); +if (ret <0 ) { +log_err ("Error: Failed to generate dfu_alt_info. (%d)\n" , ret); +return ; + } +log_debug ("Make dfu_alt_info: '%s'\n" , buf); + } +env_set ("dfu_alt_info" , buf); +} + +int fwu_plat_get_alt_num (struct udevice __always_unused *dev, +efi_guid_t *image_id,int *alt_num) +{ +return mtd_plat_get_alt_num (image_id, alt_num,"nor1" ,0 ); +} + +int fwu_plat_get_update_index (u32 *update_idx) +{ +int ret; +u32 active_idx; + + ret =fwu_get_active_index (&active_idx); + +if (ret <0 ) +return ret; + + *update_idx =1 - active_idx; + +return ret; +} + +void fwu_plat_get_bootidx (void *boot_idx) +{ +int ret; +u32 active_idx; +u32 *bootidx = boot_idx; + + ret =fwu_get_active_index (&active_idx); + +if (ret <0 ) + *bootidx =-1 ; + + *bootidx = active_idx; +} + +int board_late_init (void ) +{ +/* Make mmc available for EFI, otherwise efi subsystem +* complains "No EFI system partition" during bootup. +*/ +run_command ("mmc dev 0" ,0 ); + +return 0 ; +}configs/synquacer_developerbox_defconfig +11
-2@@ -1,10 +1,11 @@ CONFIG_ARM=y CONFIG_ARCH_SYNQUACER=y -CONFIG_SYS_TEXT_BASE=0x08200000 +CONFIG_POSITION_INDEPENDENT=y +CONFIG_SYS_TEXT_BASE=0 CONFIG_SYS_MALLOC_LEN=0x1000000 CONFIG_SYS_MALLOC_F_LEN=0x400 CONFIG_ENV_SIZE=0x30000 -CONFIG_ENV_OFFSET=0x300000 +CONFIG_ENV_OFFSET=0x580000 CONFIG_ENV_SECT_SIZE=0x10000 CONFIG_DM_GPIO=y CONFIG_DEFAULT_DEVICE_TREE="synquacer-sc2a11-developerbox"@@ -93,3 +94,11 @@ CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y CONFIG_EFI_CAPSULE_ON_DISK=y CONFIG_EFI_IGNORE_OSINDICATIONS=y CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y +CONFIG_EFI_SECURE_BOOT=y +CONFIG_BOARD_LATE_INIT=y +CONFIG_FWU_MULTI_BANK_UPDATE=y +CONFIG_DM_FWU_MDATA=y +CONFIG_FWU_MDATA_MTD=y +CONFIG_FWU_NUM_BANKS=2 +CONFIG_FWU_NUM_IMAGES_PER_BANK=1 +CONFIG_CMD_FWU_METADATA=ydoc/board/socionext/developerbox.rst +96
-0@@ -85,3 +85,99 @@ Once the flasher tool is running we are ready flash the UEFI image:: After transferring the SPI_NOR_UBOOT.fd, turn off the DSW2-7 and reset the board. + +Enable FWU Multi Bank Update +============================ + +DeveloperBox supports the FWU Multi Bank Update. You *MUST* update both *SCP firmware* and *TF-A* for this feature. This will change the layout and the boot process but you can switch back to the normal one by changing the DSW 1-4 off. + +Configure U-Boot +---------------- + +To enable the FWU Multi Bank Update on the DeveloperBox, you need to add following configurations to configs/synquacer_developerbox_defconfig :: + + CONFIG_FWU_MULTI_BANK_UPDATE=y + CONFIG_DM_FWU_MDATA=y + CONFIG_FWU_MDATA_MTD=y + CONFIG_FWU_NUM_BANKS=2 + CONFIG_FWU_NUM_IMAGES_PER_BANK=1 + CONFIG_CMD_FWU_METADATA=y + +And build it:: + + cd u-boot/ + export ARCH=arm64 + export CROSS_COMPILE=aarch64-linux-gnu- + make synqucer_developerbox_defconfig + make -j `noproc` + cd ../ + +By default, the CONFIG_FWU_NUM_BANKS and COFNIG_FWU_NUM_IMAGES_PER_BANKS are set to 2 and 1 respectively. This uses FIP (Firmware Image Package) type image which contains TF-A, U-Boot and OP-TEE (the OP-TEE is optional.) +You can use fiptool to compose the FIP image from those firmware images. + +Rebuild SCP firmware +-------------------- + +Rebuild SCP firmware which supports FWU Multi Bank Update as below:: + + cd SCP-firmware/ + OUT=./build/product/synquacer + ROMFW_FILE=$OUT/scp_romfw/$SCP_BUILD_MODE/bin/scp_romfw.bin + RAMFW_FILE=$OUT/scp_ramfw/$SCP_BUILD_MODE/bin/scp_ramfw.bin + ROMRAMFW_FILE=scp_romramfw_release.bin + + make CC=$ARM_EMB_GCC PRODUCT=synquacer MODE=release + tr "\000" "\377" < /dev/zero | dd of=${ROMRAMFW_FILE} bs=1 count=196608 + dd if=${ROMFW_FILE} of=${ROMRAMFW_FILE} bs=1 conv=notrunc seek=0 + dd if=${RAMFW_FILE} of=${ROMRAMFW_FILE} bs=1 seek=65536 + cd ../ + +And you can get the `scp_romramfw_release.bin` file + +Rebuild TF-A and FIP +-------------------- + +Rebuild TF-A which supports FWU Multi Bank Update as below:: + + cd arm-trusted-firmware/ + make CROSS_COMPILE=aarch64-linux-gnu- -j`nproc` PLAT=synquacer \ + SPD=opteed SQ_RESET_TO_BL2=1 GENERATE_COT=1 MBEDTLS_DIR=../mbedtls \ + BL33=../u-boot/u-boot.bin all fip fiptool + +And make a FIP image.:: + + cp build/synquacer/release/fip.bin SPI_NOR_NEWFIP.fd + tools/fiptool/fiptool update --tb-fw build/synquacer/release/bl2.bin SPI_NOR_NEWFIP.fd + + +UUIDs for the FWU Multi Bank Update +----------------------------------- + +FWU multi-bank update requires some UUIDs. The DeveloperBox platform uses following UUIDs. + + - Location UUID for the FIP image: 17e86d77-41f9-4fd7-87ec-a55df9842de5 + - Image type UUID for the FIP image: 10c36d7d-ca52-b843-b7b9-f9d6c501d108 + - Image UUID for Bank0 : 5a66a702-99fd-4fef-a392-c26e261a2828 + - Image UUID for Bank1 : a8f868a1-6e5c-4757-878d-ce63375ef2c0 + +These UUIDs are used for making a FWU metadata image. + +Install via flash writer +------------------------ + +As explained in above section, the new FIP image and the FWU metadata image can be installed via NOR flash writer. Note that the installation offsets for the FWU multi bank update supported firmware. + +Once the flasher tool is running we are ready flash the images.:: +Write the FIP image to the 0x600000 offset.:: + + flash rawwrite 600000 180000 + >> Send SPI_NOR_NEWFIP.fd via XMODEM (Control-A S in minicom) << + +And write the new SCP firmware.:: + + flash write cm3 + >> Send scp_romramfw_release.bin via XMODEM (Control-A S in minicom) << + +At last, turn on the DSW 3-4 on the board, and reboot. +Note that if DSW 3-4 is turned off, the DeveloperBox will boot from +the original EDK2 firmware (or non-FWU U-Boot if you already installed.)include/configs/synquacer.h +10
-0@@ -46,19 +46,29 @@/* Since U-Boot 64bit PCIe support is limited, disable 64bit MMIO support */ +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEFAULT_DFU_ALT_INFO +#else #define DEFAULT_DFU_ALT_INFO "dfu_alt_info=" \ "mtd nor1=u-boot.bin raw 200000 100000;" \ "fip.bin raw 180000 78000;" \ "optee.bin raw 500000 100000\0" +#endif /* GUIDs for capsule updatable firmware images */ #define DEVELOPERBOX_UBOOT_IMAGE_GUID \ EFI_GUID(0x53a92e83, 0x4ef4, 0x473a, 0x8b, 0x0d, \ 0xb5, 0xd8, 0xc7, 0xb2, 0xd6, 0x00) +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEVELOPERBOX_FIP_IMAGE_GUID \ + EFI_GUID(0x7d6dc310, 0x52ca, 0x43b8, 0xb7, 0xb9, \ + 0xf9, 0xd6, 0xc5, 0x01, 0xd1, 0x08) +#else #define DEVELOPERBOX_FIP_IMAGE_GUID \ EFI_GUID(0x880866e9, 0x84ba, 0x4793, 0xa9, 0x08, \ 0x33, 0xe0, 0xb9, 0x16, 0xf3, 0x98) +#endif #define DEVELOPERBOX_OPTEE_IMAGE_GUID \ EFI_GUID(0xc1b629f1, 0xce0e, 0x4894, 0x82, 0xbf, \
Re: [PATCH 5/5] fwu: DeveloperBox: add support for FWU
Quoted 37 lines · Heinrich Schuchardt
Quoted 36 lines · On 7/22/22 19:43, [email protected] wrote:
From: Jassi Brar <[email protected]>
Add code to support
FWU_MULTI_BANK_UPDATE. The platform does not have gpt-partition storage for Banks and MetaData, rather it used SPI-NOR backed mtd regions for the purpose.Signed-off-by Masami Hiramatsu <[email protected]>Signed-off-by Jassi Brar <[email protected]>---
board/socionext/developerbox/Makefile | 1 +board/socionext/developerbox/developerbox.c| 13 +++ board/socionext/developerbox/fwu_plat.c | 95 ++++++++++++++++++++ configs/synquacer_developerbox_defconfig | 13 ++- doc/board/socionext/developerbox.rst | 96 +++++++++++++++++++++ include/configs/synquacer.h | 10 +++6 files changed, 226 insertions(+), 2 deletions(-)create mode 100644
board/socionext/developerbox/fwu_plat.cboard/socionext/developerbox/Makefile +0
-0@@ -7,3 +7,4 @@ #obj-y := developerbox.o
board/socionext/developerbox/Makefile +1
-0+obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu_plat.oboard/socionext/developerbox/developerbox.c +0
-0@@ -20,6 +20,13 @@
Quoted 8 lines
board/socionext/developerbox/developerbox.c line 26
Quoted 6 lines
board/socionext/developerbox/developerbox.c +4
-0#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) struct efi_fw_image fw_images[] = { +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE) + { + .image_type_id = DEVELOPERBOX_FIP_IMAGE_GUID, + .fw_name = u"DEVELOPERBOX-FIP",The design is flawed. These fields should be moved to the device-tree.
Currently we are changing C files for each board were we enable firmware updates. Probably an even better place then the device-tree would be a Kconfig file. The only problem with Kconfig is that it does not easily allow to edit arrays. But we could use a string like:
GUID,name,index,GUID,name,index,...
Best regards
Heinrich>
Quoted 319 lines
Quoted 318 lines
board/socionext/developerbox/developerbox.c +8
-0+ .image_index = 1, + }, +#else { .image_type_id = DEVELOPERBOX_UBOOT_IMAGE_GUID, .fw_name = u"DEVELOPERBOX-UBOOT",@@ -35,12 +42,18 @@ struct efi_fw_image fw_images[] = { .fw_name = u"DEVELOPERBOX-OPTEE", .image_index = 3, }, +#endif }; struct efi_capsule_update_info update_info = { +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE ) + .dfu_string = "mtd nor1=bank0 raw 600000 400000;" + "bank1 raw a00000 400000;", +#else .dfu_string = "mtd nor1=u-boot.bin raw 200000 100000;" "fip.bin raw 180000 78000;" "optee.bin raw 500000 100000", +#endif
.images =fw_images,
};board/socionext/developerbox/fwu_plat.c new file +23
-0@@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2021, Linaro Limited +*/ + +#include <dfu.h> +#include <efi_loader.h> +#include <flash.h> +#include <fwu.h> +#include <fwu_mdata.h> +#include <malloc.h> +#include <memalign.h> +#include <mtd.h> +#include <spi.h> +#include <spi_flash.h> +#include <uuid.h> + +#include <linux/errno.h> +#include <linux/types.h> +#include <u-boot/crc.h> + +#define DFU_ALT_BUF_LEN 256 +#define DFU_ALT_NUM_MAX (CONFIG_FWU_NUM_IMAGES_PER_BANK *
CONFIG_FWU_NUM_BANKS)board/socionext/developerbox/fwu_plat.c new file +21
-0+ +/* Generate dfu_alt_info from partitions */ +void set_dfu_alt_info (char *interface,char *devstr) +{ + int ret; + struct mtd_info *mtd; + static char *buf = NULL; + + if (!buf) { + buf = malloc_cache_aligned(DFU_ALT_BUF_LEN); + memset(buf, 0, DFU_ALT_BUF_LEN); + + mtd_probe_devices(); + + mtd = get_mtd_device_nm("nor1"); + if (IS_ERR_OR_NULL(mtd)) + return; + + ret = fwu_gen_alt_info_from_mtd(buf, DFU_ALT_BUF_LEN, mtd); + if (ret < 0) { + log_err("Error: Failed to generate dfu_alt_info. (%d)\n",ret);
+ return;
+ }
+log_debug("Make dfu_alt_info: '%s'\n", buf); + }
+env_set("dfu_alt_info", buf);board/socionext/developerbox/fwu_plat.c new file +46
-0+} + +int fwu_plat_get_alt_num (struct udevice __always_unused *dev, + efi_guid_t *image_id, int *alt_num) +{ + return mtd_plat_get_alt_num(image_id, alt_num, "nor1", 0); +} + +int fwu_plat_get_update_index (u32 *update_idx) +{ + int ret; + u32 active_idx; + + ret = fwu_get_active_index(&active_idx); + + if (ret < 0) + return ret; + + *update_idx = 1 - active_idx; + + return ret; +} + +void fwu_plat_get_bootidx (void *boot_idx) +{ + int ret; + u32 active_idx; + u32 *bootidx = boot_idx; + + ret = fwu_get_active_index(&active_idx); + + if (ret < 0) + *bootidx = -1; + + *bootidx = active_idx; +} + +int board_late_init (void ) +{ + /* Make mmc available for EFI, otherwise efi subsystem + * complains "No EFI system partition" during bootup. + */ + run_command("mmc dev 0", 0); + + return 0; +}configs/synquacer_developerbox_defconfig +0
-0@@ -1,10 +1,11 @@
CONFIG_ARM=y
CONFIG_ARCH_SYNQUACER=yconfigs/synquacer_developerbox_defconfig +2
-1-CONFIG_SYS_TEXT_BASE=0x08200000 +CONFIG_POSITION_INDEPENDENT=y +CONFIG_SYS_TEXT_BASE=0
CONFIG_SYS_MALLOC_LEN=0x1000000
CONFIG_SYS_MALLOC_F_LEN=0x400
CONFIG_ENV_SIZE=0x30000configs/synquacer_developerbox_defconfig +1
-1-CONFIG_ENV_OFFSET=0x300000 +CONFIG_ENV_OFFSET=0x580000
CONFIG_ENV_SECT_SIZE=0x10000
CONFIG_DM_GPIO=yCONFIG_DEFAULT_DEVICE_TREE="synquacer-sc2a11-developerbox"configs/synquacer_developerbox_defconfig +0
-0@@ -93,3 +94,11 @@ CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y
CONFIG_EFI_CAPSULE_ON_DISK=y
CONFIG_EFI_IGNORE_OSINDICATIONS=y
CONFIG_EFI_CAPSULE_FIRMWARE_RAW=yconfigs/synquacer_developerbox_defconfig +8
-0+CONFIG_EFI_SECURE_BOOT=y +CONFIG_BOARD_LATE_INIT=y +CONFIG_FWU_MULTI_BANK_UPDATE=y +CONFIG_DM_FWU_MDATA=y +CONFIG_FWU_MDATA_MTD=y +CONFIG_FWU_NUM_BANKS=2 +CONFIG_FWU_NUM_IMAGES_PER_BANK=1 +CONFIG_CMD_FWU_METADATA=ydoc/board/socionext/developerbox.rst +0
-0@@ -85,3 +85,99 @@ Once the flasher tool is running we are ready flashthe UEFI image::
After transferring the SPI_NOR_UBOOT.fd, turn off the DSW2-7 and reset the board.
doc/board/socionext/developerbox.rst +5
-0+ +Enable FWU Multi Bank Update +============================ + +DeveloperBox supports the FWU Multi Bank Update. You *MUST* updateboth *SCP firmware* and *TF-A* for this feature. This will change the layout and the boot process but you can switch back to the normal one by changing the DSW 1-4 off.
doc/board/socionext/developerbox.rst +5
-0+ +Configure U-Boot +---------------- + +To enable the FWU Multi Bank Update on the DeveloperBox, you need toadd following configurations to
configs/synquacer_developerbox_defconfig ::doc/board/socionext/developerbox.rst +18
-0+ + CONFIG_FWU_MULTI_BANK_UPDATE=y + CONFIG_DM_FWU_MDATA=y + CONFIG_FWU_MDATA_MTD=y + CONFIG_FWU_NUM_BANKS=2 + CONFIG_FWU_NUM_IMAGES_PER_BANK=1 + CONFIG_CMD_FWU_METADATA=y + +And build it:: + + cd u-boot/ + export ARCH=arm64 + export CROSS_COMPILE=aarch64-linux-gnu- + make synqucer_developerbox_defconfig + make -j `noproc` + cd ../ + +By default, the CONFIG_FWU_NUM_BANKS and
COFNIG_FWU_NUM_IMAGES_PER_BANKSare set to 2 and 1 respectively. This uses FIP (Firmware Image Package) type image which contains TF-A, U-Boot and OP-TEE (the OP-TEE is optional.)doc/board/socionext/developerbox.rst +15
-0+You can use fiptool to compose the FIP image from those firmware images. + +Rebuild SCP firmware +-------------------- + +Rebuild SCP firmware which supports FWU Multi Bank Update as below:: + + cd SCP-firmware/ + OUT=./build/product/synquacer + ROMFW_FILE=$OUT/scp_romfw/$SCP_BUILD_MODE/bin/scp_romfw.bin + RAMFW_FILE=$OUT/scp_ramfw/$SCP_BUILD_MODE/bin/scp_ramfw.bin + ROMRAMFW_FILE=scp_romramfw_release.bin + + make CC=$ARM_EMB_GCC PRODUCT=synquacer MODE=release + tr "\000" "\377" < /dev/zero | dd of=${ROMRAMFW_FILE} bs=1count=196608
+ dd if=${ROMFW_FILE} of=${ROMRAMFW_FILE} bs=1 conv=notrunc seek=0 + dd if=${RAMFW_FILE} of=${ROMRAMFW_FILE} bs=1 seek=65536 + cd ../doc/board/socionext/developerbox.rst +11
-0+ +And you can get the `scp_romramfw_release.bin` file + +Rebuild TF-A and FIP +-------------------- + +Rebuild TF-A which supports FWU Multi Bank Update as below:: + + cd arm-trusted-firmware/ + make CROSS_COMPILE=aarch64-linux-gnu- -j`nproc` PLAT=synquacer \ + SPD=opteed SQ_RESET_TO_BL2=1 GENERATE_COT=1MBEDTLS_DIR=../mbedtls \
+ BL33=../u-boot/u-boot.bin all fip fiptooldoc/board/socionext/developerbox.rst +5
-0+ +And make a FIP image.:: + + cp build/synquacer/release/fip.bin SPI_NOR_NEWFIP.fd + tools/fiptool/fiptool update --tb-fwbuild/synquacer/release/bl2.bin SPI_NOR_NEWFIP.fd
doc/board/socionext/developerbox.rst +6
-0+ + +UUIDs for the FWU Multi Bank Update +----------------------------------- + +FWU multi-bank update requires some UUIDs. The DeveloperBox platformuses following UUIDs.
+
+ - Location UUID for the FIP image: 17e86d77-41f9-4fd7-87ec-a55df9842de5
+ - Image type UUID for the FIP image:
10c36d7d-ca52-b843-b7b9-f9d6c501d108
+ - Image UUID for Bank0 : 5a66a702-99fd-4fef-a392-c26e261a2828
+ - Image UUID for Bank1 : a8f868a1-6e5c-4757-878d-ce63375ef2c0doc/board/socionext/developerbox.rst +7
-0+ +These UUIDs are used for making a FWU metadata image. + +Install via flash writer +------------------------ + +As explained in above section, the new FIP image and the FWU metadataimage can be installed via NOR flash writer. Note that the installation offsets for the FWU multi bank update supported firmware.
doc/board/socionext/developerbox.rst +11
-0+ +Once the flasher tool is running we are ready flash the images.:: +Write the FIP image to the 0x600000 offset.:: + + flash rawwrite 600000 180000 + >> Send SPI_NOR_NEWFIP.fd via XMODEM (Control-A S in minicom) << + +And write the new SCP firmware.:: + + flash write cm3 + >> Send scp_romramfw_release.bin via XMODEM (Control-A S inminicom) <<
doc/board/socionext/developerbox.rst +4
-0+ +At last, turn on the DSW 3-4 on the board, and reboot. +Note that if DSW 3-4 is turned off, the DeveloperBox will boot from +the original EDK2 firmware (or non-FWU U-Boot if you already installed.)include/configs/synquacer.h +0
-0@@ -46,19 +46,29 @@ /* Since U-Boot 64bit PCIe support is limited, disable 64bit MMIOsupport */
include/configs/synquacer.h +3
-0+#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEFAULT_DFU_ALT_INFO +#else #define
DEFAULT_DFU_ALT_INFO"dfu_alt_info=" \
"mtd nor1=u-boot.bin raw 200000 100000;" \
"fip.bin raw 180000 78000;" \
"optee.bin raw 500000 100000\0"
+#endif/* GUIDs for capsule updatable firmware images */ #define
DEVELOPERBOX_UBOOT_IMAGE_GUID\
EFI_GUID(0x53a92e83,0x4ef4,0x473a,0x8b,0x0d, \
0xb5,0xd8,0xc7,0xb2,0xd6,0x00)include/configs/synquacer.h +5
-0+#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEVELOPERBOX_FIP_IMAGE_GUID \ + EFI_GUID(0x7d6dc310, 0x52ca, 0x43b8, 0xb7, 0xb9, \ + 0xf9, 0xd6, 0xc5, 0x01, 0xd1, 0x08) +#else #define
DEVELOPERBOX_FIP_IMAGE_GUID\
EFI_GUID(0x880866e9,0x84ba,0x4793,0xa9,0x08, \
0x33,0xe0,0xb9,0x16,0xf3,0x98) +#endif#define
DEVELOPERBOX_OPTEE_IMAGE_GUID\
EFI_GUID(0xc1b629f1,0xce0e,0x4894,0x82,0xbf, \
Re: [PATCH 5/5] fwu: DeveloperBox: add support for FWU
Quoted 18 lines · Heinrich Schuchardt
Quoted 9 lines · On 7/22/22 19:43, [email protected] wrote:
Quoted 8 lines
board/socionext/developerbox/developerbox.c +0
-0@@ -20,6 +20,13 @@Quoted 8 lines
board/socionext/developerbox/developerbox.c line 26
Quoted 6 lines
board/socionext/developerbox/developerbox.c +4
-0#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) struct efi_fw_image fw_images[] = { +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE) + { + .image_type_id = DEVELOPERBOX_FIP_IMAGE_GUID, + .fw_name = u"DEVELOPERBOX-FIP",The design is flawed. These fields should be moved to the device-tree.
Quoted 7 lines
Currently we are changing C files for each board were we enable firmware updates. Probably an even better place then the device-tree would be a
Kconfigfile. The only problem withKconfigis that it does not easily allow to edit arrays. But we could use a string like:GUID,name,index,GUID,name,index,...
Probably. But there already exists the structure that this patch only adds an entry to. Moving that structure into dt or kconfig should be a separate task of different context.
Also right now I don't want to diverge from gpt based STM's implementation which does the same thing.
thanks
Re: [PATCH 0/5] FWU: Add support for mtd backed feature on DeveloperBox
In reply to [email protected]hi Jassi,
Quoted 12 lines · On Fri, 22 Jul 2022 at 23:12, <[email protected]> wrote:
From: Jassi Brar <[email protected]>
The mtd and synquacer (developerbox) support was dropped from v6[1] This patchset re-introduces the support over last v7[2] submission of the patchset.
All the comments on this code over v5 submission have been addressed. Moving forward a changelog will be maintained.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Quoted 8 lines
Jassi Brar (2):
dt: fwu: developerbox: enable fwu banks and mdata regions
fwu: DeveloperBox: add support for FWUSughosh Ganu (3):
dt/bindings: Add bindings for FWU Metadata mtd storage
FWU: Add FWU metadata access driver for MTD storage regions
FWU: mtd: Add helper functions for accessing FWU metadata
All the above patches have been authored by Masami Hiramatsu. I think you should change the author for these patches. Also, there were a few more patches from Masami, like the documentation for the feature on the Synquacer platform, and addition of the tool, mkfwumdata, for generating the FWU metadata which I do not see in this series. Do you plan to send those separately?
-sughosh
Quoted 23 lines
.../synquacer-sc2a11-developerbox-u-boot.dtsi | 22 +- board/socionext/developerbox/Makefile | 1 + board/socionext/developerbox/developerbox.c | 13 + board/socionext/developerbox/fwu_plat.c | 95 ++++++ configs/synquacer_developerbox_defconfig | 13 +- doc/board/socionext/developerbox.rst | 96 ++++++ .../firmware/fwu-mdata-mtd.yaml | 38 +++ drivers/fwu-mdata/Kconfig | 8 + drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++++++++++++++++++ include/configs/synquacer.h | 10 + lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 173 ++++++++++ 13 files changed, 776 insertions(+), 3 deletions(-) create mode 100644 board/socionext/developerbox/fwu_plat.c create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml create mode 100644 drivers/fwu-mdata/fwu_mdata_mtd.c create mode 100644 lib/fwu_updates/fwu_mtd.c--
2.25.1
Re: [PATCH 0/5] FWU: Add support for mtd backed feature on DeveloperBox
Hi Sughosh,
Quoted 20 lines · Sughosh Ganu
hi Jassi,
Quoted 16 lines · On Fri, 22 Jul 2022 at 23:12, <[email protected]> wrote:
From: Jassi Brar <[email protected]>
The mtd and synquacer (developerbox) support was dropped from v6[1] This patchset re-introduces the support over last v7[2] submission of the patchset.
All the comments on this code over v5 submission have been addressed. Moving forward a changelog will be maintained.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/Jassi Brar (2):
dt: fwu: developerbox: enable fwu banks and mdata regions
fwu: DeveloperBox: add support for FWU
Quoted 8 lines
Quoted 4 lines
Sughosh Ganu (3):
dt/bindings: Add bindings for FWU Metadata mtd storage
FWU: Add FWU metadata access driver for MTD storage regions
FWU: mtd: Add helper functions for accessing FWU metadataAll the above patches have been authored by Masami Hiramatsu. I think you should change the author for these patches.
oops... I used the '-c' option to carry over the log from your patches and forgot to update the author.
Will do. thanks.
Quoted 6 lines
Also, there were a few
more patches from Masami, like the documentation for the feature on the Synquacer platform, and addition of the tool, mkfwumdata, for generating the FWU metadata which I do not see in this series. Do you plan to send those separately?
yes.
Re: [PATCH 0/5] FWU: Add support for mtd backed feature on DeveloperBox
In reply to [email protected]Quoted 10 lines · On 7/22/22 19:42, [email protected] wrote:
From: Jassi Brar <[email protected]>
The mtd and synquacer (developerbox) support was dropped from v6[1] This patchset re-introduces the support over last v7[2] submission of the patchset.
All the comments on this code over v5 submission have been addressed. Moving forward a changelog will be maintained.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
This new feature deserves a test that can executed in Gitlab.
Preferably we would test on the sandbox. But testing on QEMU using an emulated flash would be another option.
Best regards
Heinrich
Quoted 29 lines
Jassi Brar (2):
dt: fwu: developerbox: enable fwu banks and mdata regions
fwu: DeveloperBox: add support for FWUSughosh Ganu (3):
dt/bindings: Add bindings for FWU Metadata mtd storage
FWU: Add FWU metadata access driver for MTD storage regions
FWU: mtd: Add helper functions for accessing FWU metadata.../synquacer-sc2a11-developerbox-u-boot.dtsi | 22 +- board/socionext/developerbox/Makefile | 1 + board/socionext/developerbox/developerbox.c | 13 + board/socionext/developerbox/fwu_plat.c | 95 ++++++ configs/synquacer_developerbox_defconfig | 13 +- doc/board/socionext/developerbox.rst | 96 ++++++ .../firmware/fwu-mdata-mtd.yaml | 38 +++ drivers/fwu-mdata/Kconfig | 8 + drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++++++++++++++++++ include/configs/synquacer.h | 10 + lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 173 ++++++++++ 13 files changed, 776 insertions(+), 3 deletions(-)create mode 100644
board/socionext/developerbox/fwu_plat.ccreate mode 100644doc/device-tree-bindings/firmware/fwu-mdata-mtd.yamlcreate mode 100644drivers/fwu-mdata/fwu_mdata_mtd.c
create mode 100644lib/fwu_updates/fwu_mtd.c
Re: [PATCH 0/5] FWU: Add support for mtd backed feature on DeveloperBox
In reply to [email protected]Quoted 4 lines · On 7/22/22 19:42, [email protected] wrote:
From: Jassi Brar <[email protected]>
The mtd and synquacer (developerbox) support was dropped from v6[1] This patchset re-introduces the support over last v7[2] submission of the patchset.
So this series should have been marked v8?
Quoted 6 lines
All the comments on this code over v5 submission have been addressed. Moving forward a changelog will be maintained.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
How does this series relate to
[PATCH v8 00/13] FWU: Add FWU Multi Bank Update feature support
https://lore.kernel.org/all/[email protected]/?
Is it superseded by that series?
This series has "FWU metadata on MTD device without GPT" while the other has "FWU metadata on device with GPT partitioned layout".
Do we need both?
Best regards
Heinrich
Quoted 29 lines
Jassi Brar (2):
dt: fwu: developerbox: enable fwu banks and mdata regions
fwu: DeveloperBox: add support for FWUSughosh Ganu (3):
dt/bindings: Add bindings for FWU Metadata mtd storage
FWU: Add FWU metadata access driver for MTD storage regions
FWU: mtd: Add helper functions for accessing FWU metadata.../synquacer-sc2a11-developerbox-u-boot.dtsi | 22 +- board/socionext/developerbox/Makefile | 1 + board/socionext/developerbox/developerbox.c | 13 + board/socionext/developerbox/fwu_plat.c | 95 ++++++ configs/synquacer_developerbox_defconfig | 13 +- doc/board/socionext/developerbox.rst | 96 ++++++ .../firmware/fwu-mdata-mtd.yaml | 38 +++ drivers/fwu-mdata/Kconfig | 8 + drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++++++++++++++++++ include/configs/synquacer.h | 10 + lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 173 ++++++++++ 13 files changed, 776 insertions(+), 3 deletions(-)create mode 100644
board/socionext/developerbox/fwu_plat.ccreate mode 100644doc/device-tree-bindings/firmware/fwu-mdata-mtd.yamlcreate mode 100644drivers/fwu-mdata/fwu_mdata_mtd.c
create mode 100644lib/fwu_updates/fwu_mtd.c
Re: [PATCH 0/5] FWU: Add support for mtd backed feature on DeveloperBox
hello Heinrich,
Quoted 21 lines · Heinrich Schuchardt
Quoted 4 lines · On 7/22/22 19:42, [email protected] wrote:
From: Jassi Brar <[email protected]>
The mtd and synquacer (developerbox) support was dropped from v6[1] This patchset re-introduces the support over last v7[2] submission of the patchset.
So this series should have been marked v8?
Quoted 6 lines
All the comments on this code over v5 submission have been addressed. Moving forward a changelog will be maintained.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/How does this series relate to
[PATCH v8 00/13] FWU: Add FWU Multi Bank Update feature support
https://lore.kernel.org/all/[email protected]/?
Quoted 6 lines
Is it superseded by that series?
This series has "FWU metadata on MTD device without GPT" while the other has "FWU metadata on device with GPT partitioned layout".
Do we need both?
Yes, we need both the patch series. The first series([PATCH v8 00/13]
FWU: Add FWU Multi Bank Update feature support) adds support for the feature and for platforms with GPT partitioning layout, and is enabling the feature on the ST DK2 board. The second series is adding support for the feature on MTD partition based devices and enabling the feature on the Synquacer board.
-sughosh
Quoted 35 lines
Best regards
Heinrich
Quoted 29 lines
Jassi Brar (2):
dt: fwu: developerbox: enable fwu banks and mdata regions
fwu: DeveloperBox: add support for FWUSughosh Ganu (3):
dt/bindings: Add bindings for FWU Metadata mtd storage
FWU: Add FWU metadata access driver for MTD storage regions
FWU: mtd: Add helper functions for accessing FWU metadata.../synquacer-sc2a11-developerbox-u-boot.dtsi | 22 +- board/socionext/developerbox/Makefile | 1 + board/socionext/developerbox/developerbox.c | 13 + board/socionext/developerbox/fwu_plat.c | 95 ++++++ configs/synquacer_developerbox_defconfig | 13 +- doc/board/socionext/developerbox.rst | 96 ++++++ .../firmware/fwu-mdata-mtd.yaml | 38 +++ drivers/fwu-mdata/Kconfig | 8 + drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++++++++++++++++++ include/configs/synquacer.h | 10 + lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 173 ++++++++++ 13 files changed, 776 insertions(+), 3 deletions(-)create mode 100644
board/socionext/developerbox/fwu_plat.ccreate mode 100644doc/device-tree-bindings/firmware/fwu-mdata-mtd.yamlcreate mode 100644drivers/fwu-mdata/fwu_mdata_mtd.c
create mode 100644lib/fwu_updates/fwu_mtd.c