Skip to contentSkip to conversation

FWU: Add FWU Multi Bank Update for DeveloerBox

RFC PATCH In review Masami Hiramatsu 1 participant 10 messages Feb 17, 2022 – Feb 21, 2022 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

v2 cover FWU: Add FWU Multi Bank Update for DeveloerBox

Hi,

Here is the 2nd version of RFC series of patches for the FWU Multi Bank Update support for the DeveloperBox platform.
This series depends on Sughosh's Multi Bank Update v4 [1].

[1] https://lore.kernel.org/all/[email protected]/T/#u

Unlike the STM32MP board, DeveloperBox (SynQuacer) loads the firmware from SPI NOR flash. Thus it doesn't use GPT partitions to store the firmware banks and the FWU metadata. Instead, it stores those data at fixed address areas on SPI NOR flash. I carefully chose the areas which doesn't overlap the previous firmware and EDK2.

This adds FWU metadata SF driver for this FWU multi bank support on SPI flash without GPT. This is identified by "u-boot,fwu-mdata-sf". The last patch adds the DT bindings in YAML.

Since there is no GPT, the location GUID for images and the image GUID for banks are Null GUID. I will fix this with uuid property for fixed-partition devicetree afterwards.

And the SynQuacer also does not have any non-volatile register. Thus this allocates the platform defined boot index on the SPI flash too.

NOTE: To use this series, you also need to update SCP firmware[2] and TF-A[3] on the DeveloperBox. Those are under cleaning up.

[2] https://git.linaro.org/people/masami.hiramatsu/SCP-firmware.git/
[3] https://git.linaro.org/people/masami.hiramatsu/arm-trusted-firmware.git/

Thank you,

---

Masami Hiramatsu (8):
FWU: Calculate CRC32 in fwu_update_mdata()
FWU: Free metadata copy if gpt_get_mdata() failed
synquacer: Update for TBBR based new FIP layout dt/bindings: firmware: Add FWU metadata on SPI flash binding
FWU: Add FWU metadata access driver for SPI flash
FWU: synquacer: Add FWU Multi bank update support for DeveloperBox
FWU: synquacer: Initialize broken metadata
configs: synquacer: Add FWU support for DeveloperBox

 .../dts/synquacer-sc2a11-developerbox-u-boot.dtsi  |   33 ++
 board/socionext/developerbox/Kconfig               |   24 ++
 board/socionext/developerbox/Makefile              |    1 
 board/socionext/developerbox/fwu_plat.c            |  238 ++++++++++++++++
 configs/synquacer_developerbox_defconfig           |   12 +
 .../firmware/fwu-mdata-sf.yaml                     |   38 +++
 drivers/fwu-mdata/Kconfig                          |    9 +
 drivers/fwu-mdata/Makefile                         |    1 
 drivers/fwu-mdata/fwu-mdata-uclass.c               |   57 +---
 drivers/fwu-mdata/fwu_mdata_gpt_blk.c              |   49 ++-
 drivers/fwu-mdata/fwu_mdata_sf.c                   |  294 ++++++++++++++++++++
 include/configs/synquacer.h                        |   14 +
 include/fwu.h                                      |    2 
 13 files changed, 698 insertions(+), 74 deletions(-)
 create mode 100644 board/socionext/developerbox/fwu_plat.c
 create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-sf.yaml
 create mode 100644 drivers/fwu-mdata/fwu_mdata_sf.c

--
Masami Hiramatsu <[email protected]>

#1 lore raw

RFC PATCH v2 1/8 FWU: Calculate CRC32 in fwu_update_mdata()

To avoid calculating crc32 in several places, do it in fwu_update_mdata(). This also ensures the mdata crc32 is always sane.

---
 drivers/fwu-mdata/fwu-mdata-uclass.c |   33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)
drivers/fwu-mdata/fwu-mdata-uclass.c +10 -23
index 64b3051ecf..b98eda3789 100644
@@ -115,7 +115,6 @@ out:
 int fwu_update_active_index(u32 active_idx)
 {
 	int ret;
-	void *buf;
 	struct fwu_mdata *mdata = NULL;
 
 	if (active_idx > CONFIG_FWU_NUM_BANKS - 1) {
@@ -136,14 +135,6 @@ int fwu_update_active_index(u32 active_idx)
 	mdata->previous_active_index = mdata->active_index;
 	mdata->active_index = active_idx;
 
-	/*
-	 * Calculate the crc32 for the updated FWU metadata
-	 * and put the updated value in the FWU metadata crc32
-	 * field
-	 */
-	buf = &mdata->version;
-	mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32));
-
 	/*
 	 * Now write this updated FWU metadata to both the
 	 * FWU metadata partitions
@@ -233,7 +224,6 @@ int fwu_mdata_check(void)
 int fwu_revert_boot_index(void)
 {
 	int ret;
-	void *buf;
 	u32 cur_active_index;
 	struct fwu_mdata *mdata = NULL;
 
@@ -251,14 +241,6 @@ int fwu_revert_boot_index(void)
 	mdata->active_index = mdata->previous_active_index;
 	mdata->previous_active_index = cur_active_index;
 
-	/*
-	 * Calculate the crc32 for the updated FWU metadata
-	 * and put the updated value in the FWU metadata crc32
-	 * field
-	 */
-	buf = &mdata->version;
-	mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32));
-
 	/*
 	 * Now write this updated FWU metadata to both the
 	 * FWU metadata partitions
@@ -293,7 +275,6 @@ out:
 static int fwu_set_clear_image_accept(efi_guid_t *img_type_id,
 				      u32 bank, u8 action)
 {
-	void *buf;
 	int ret, i;
 	u32 nimages;
 	struct fwu_mdata *mdata = NULL;
@@ -316,10 +297,6 @@ static int fwu_set_clear_image_accept(efi_guid_t *img_type_id,
 			else
 				img_bank_info->accepted = 0;
 
-			buf = &mdata->version;
-			mdata->crc32 = crc32(0, buf, sizeof(*mdata) -
-					     sizeof(u32));
-
 			ret = fwu_update_mdata(mdata);
 			goto out;
 		}
@@ -425,6 +402,16 @@ int fwu_update_mdata(struct fwu_mdata *mdata)
 		return -ENOSYS;
 	}
 
+	if (!mdata)
+		return -EINVAL;
+	/*
+	 * Calculate the crc32 for the updated FWU metadata
+	 * and put the updated value in the FWU metadata crc32
+	 * field
+	 */
+	mdata->crc32 = crc32(0, (const unsigned char *)&mdata->version,
+			     sizeof(*mdata) - sizeof(u32));
+
 	return ops->update_mdata(dev, mdata);
 }
 
#2 lore raw

RFC PATCH v2 2/8 FWU: Free metadata copy if gpt_get_mdata() failed

In reply to Masami Hiramatsu

It is better if a function which returns an error then release all allocated memory resources. This simplifies the mind model and less chance to forgot to free memory and double free.

---
 drivers/fwu-mdata/fwu-mdata-uclass.c  |   24 ++++++----------
 drivers/fwu-mdata/fwu_mdata_gpt_blk.c |   49 ++++++++++++++++++---------------
 2 files changed, 36 insertions(+), 37 deletions(-)
drivers/fwu-mdata/fwu-mdata-uclass.c +9 -15
index b98eda3789..c1cd77243f 100644
@@ -79,12 +79,12 @@ int fwu_verify_mdata(struct fwu_mdata *mdata, bool pri_part)
 int fwu_get_active_index(u32 *active_idx)
 {
 	int ret;
-	struct fwu_mdata *mdata = NULL;
+	struct fwu_mdata *mdata;
 
 	ret = fwu_get_mdata(&mdata);
 	if (ret < 0) {
 		log_err("Unable to get valid FWU metadata\n");
-		goto out;
+		return ret;
 	}
 
 	/*
@@ -96,8 +96,6 @@ int fwu_get_active_index(u32 *active_idx)
 		log_err("Active index value read is incorrect\n");
 		ret = -EINVAL;
 	}
-
-out:
 	free(mdata);
 
 	return ret;
@@ -115,17 +113,17 @@ out:
 int fwu_update_active_index(u32 active_idx)
 {
 	int ret;
-	struct fwu_mdata *mdata = NULL;
+	struct fwu_mdata *mdata;
 
 	if (active_idx > CONFIG_FWU_NUM_BANKS - 1) {
 		log_err("Active index value to be updated is incorrect\n");
-		return -1;
+		return -EINVAL;
 	}
 
 	ret = fwu_get_mdata(&mdata);
 	if (ret < 0) {
 		log_err("Unable to get valid FWU metadata\n");
-		goto out;
+		return ret;
 	}
 
 	/*
@@ -144,8 +142,6 @@ int fwu_update_active_index(u32 active_idx)
 		log_err("Failed to update FWU metadata partitions\n");
 		ret = -EIO;
 	}
-
-out:
 	free(mdata);
 
 	return ret;
@@ -225,12 +221,12 @@ int fwu_revert_boot_index(void)
 {
 	int ret;
 	u32 cur_active_index;
-	struct fwu_mdata *mdata = NULL;
+	struct fwu_mdata *mdata;
 
 	ret = fwu_get_mdata(&mdata);
 	if (ret < 0) {
 		log_err("Unable to get valid FWU metadata\n");
-		goto out;
+		return ret;
 	}
 
 	/*
@@ -250,8 +246,6 @@ int fwu_revert_boot_index(void)
 		log_err("Failed to update FWU metadata partitions\n");
 		ret = -EIO;
 	}
-
-out:
 	free(mdata);
 
 	return ret;
@@ -277,14 +271,14 @@ static int fwu_set_clear_image_accept(efi_guid_t *img_type_id,
 {
 	int ret, i;
 	u32 nimages;
-	struct fwu_mdata *mdata = NULL;
+	struct fwu_mdata *mdata;
 	struct fwu_image_entry *img_entry;
 	struct fwu_image_bank_info *img_bank_info;
 
 	ret = fwu_get_mdata(&mdata);
 	if (ret < 0) {
 		log_err("Unable to get valid FWU metadata\n");
-		goto out;
+		return ret;
 	}
 
 	nimages = CONFIG_FWU_NUM_IMAGES_PER_BANK;
drivers/fwu-mdata/fwu_mdata_gpt_blk.c +27 -22

73 lines not on this page · raw message

#3 lore raw

RFC PATCH v2 3/8 synquacer: Update for TBBR based new FIP layout

In reply to Masami Hiramatsu

This changes SPI NOR flash partition layout for TBBR and also make the U-Boot as position independent executable again because BL33 is loaded on the memory.

With enabling TBBR, TF-A BL2 loads all BL3x images from FIP image, and the U-Boot image is added to the FIP image as BL33, and loaded to memory when boot instead of XIP on SPI NOR flash. To avoid mixing up with the legacy images, this new FIP image is stored on unused area (0x600000-) and the U-Boot env vars are also stored at 0x580000 so that it will not break existing EDK2 area.

---
 .../dts/synquacer-sc2a11-developerbox-u-boot.dtsi  |   26 ++++++++++++++------
 configs/synquacer_developerbox_defconfig           |    5 ++--
 include/configs/synquacer.h                        |    4 +--
 3 files changed, 22 insertions(+), 13 deletions(-)
arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi +18 -8
index 7a56116d6f..095727e03c 100644
@@ -56,7 +56,7 @@
 				};
 
 				partition@180000 {
-					label = "FIP-TFA";
+					label = "LegacyFIP";
 					reg = <0x180000 0x78000>;
 				};
 
@@ -66,18 +66,28 @@
 				};
 
 				partition@200000 {
-					label = "U-Boot";
-					reg = <0x200000 0x100000>;
+					label = "EDK2";
+					reg = <0x200000 0x200000>;
 				};
 
-				partition@300000 {
-					label = "UBoot-Env";
-					reg = <0x300000 0x100000>;
+				partition@400000 {
+					label = "EDK2-Env";
+					reg = <0x400000 0x100000>;
 				};
 
 				partition@500000 {
-					label = "Ex-OPTEE";
-					reg = <0x500000 0x200000>;
+					label = "Metadata";
+					reg = <0x500000 0x80000>;
+				};
+
+				partition@580000 {
+					label = "UBoot-Env";
+					reg = <0x580000 0x80000>;
+				};
+
+				partition@600000 {
+					label = "FIP";
+					reg = <0x600000 0x400000>;
 				};
 			};
 		};
configs/synquacer_developerbox_defconfig +3 -2
index 4fb0fba441..692919e1f5 100644
@@ -1,9 +1,10 @@
 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_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"
include/configs/synquacer.h +1 -3
index 3d099b4f11..1b6e6d011e 100644
@@ -52,9 +52,7 @@
 /* #define CONFIG_SYS_PCI_64BIT		1 */
 
 #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"
+			"mtd nor1=fip.bin raw 600000 400000\0"
 
 /* Distro boot settings */
 #ifndef CONFIG_SPL_BUILD
#4 lore raw

RFC PATCH v2 4/8 dt/bindings: firmware: Add FWU metadata on SPI flash binding

In reply to Masami Hiramatsu

Add a devicetree-binding YAML file for the FWU metadata on SPI Flash without GPT.

---
 .../firmware/fwu-mdata-sf.yaml                     |   38 ++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-sf.yaml
doc/device-tree-bindings/firmware/fwu-mdata-sf.yaml new file +38 -0
new file mode 100644
index 0000000000..3d8726231f
@@ -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 SPI Flash without GPT
+
+maintainers:
+ - Masami Hiramatsu <[email protected]>
+
+properties:
+  compatible:
+    items:
+      - const: u-boot,fwu-mdata-sf
+
+  fwu-mdata-store:
+    maxItems: 1
+    description: Phandle of the SPI NOR flash 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-sf";
+        fwu-mdata-store = <&spi-flash>;
+        mdata-offsets = <0x500000 0x530000>;
+    };
#5 lore raw

RFC PATCH v2 5/8 FWU: Add FWU metadata access driver for SPI flash

In reply to Masami Hiramatsu

For the platform which doesn't have GPT partitions for the firmware but on SPI flash, the FWU metadata is stored on SPI flash as raw image at specific offset. This driver gives the access methods for those metadata information on the SPI flash.

---
 drivers/fwu-mdata/Kconfig        |    9 +
 drivers/fwu-mdata/Makefile       |    1 
 drivers/fwu-mdata/fwu_mdata_sf.c |  294 ++++++++++++++++++++++++++++++++++++++
 include/fwu.h                    |    2 
 4 files changed, 306 insertions(+)
 create mode 100644 drivers/fwu-mdata/fwu_mdata_sf.c
drivers/fwu-mdata/Kconfig +9 -0
index d5edef19d6..9bed3e9c1e 100644
@@ -14,3 +14,12 @@ config FWU_MDATA_GPT_BLK
 	help
 	  Enable support for accessing FWU Metadata on GPT partitioned
 	  block devices.
+
+config FWU_MDATA_SF
+	bool "Enable FWU Multi Bank Update for SPI Flash"
+	depends on DM_FWU_MDATA
+	help
+	  Enable FWU Multi Bank Update for SPI flash driver. This
+	  driver does not depend on GPT. Instead, the platform must
+	  provide some APIs and define the offset of the primary and
+	  the secondary metadata.
drivers/fwu-mdata/Makefile +1 -0
index 12a5b4fe04..f8db25ab69 100644
@@ -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_SF) += fwu_mdata_sf.o
drivers/fwu-mdata/fwu_mdata_sf.c new file +294 -0

294 lines not on this page · raw message

include/fwu.h +2 -0
index 88dc4a4b9a..f5ac3f6d2e 100644
@@ -66,5 +66,7 @@ int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank);
 int fwu_plat_get_update_index(u32 *update_idx);
 int fwu_plat_get_alt_num(struct udevice *dev, void *identifier);
 void fwu_plat_get_bootidx(void *boot_idx);
+int fwu_plat_get_image_alt_num(efi_guid_t image_type_id, u32 update_bank,
+			       int *alt_no);
 
 #endif /* _FWU_H_ */
#6 lore raw

RFC PATCH v2 6/8 FWU: synquacer: Add FWU Multi bank update support for DeveloperBox

In reply to Masami Hiramatsu

The DeveloperBox platform can support the FWU Multi bank update. SCP firmware will switch the boot mode by DSW3-4 and load the Multi bank update supported TF-A BL2 from 0x600000 offset on the SPI flash. Thus it can co-exist with the legacy boot mode (legacy U-Boot or EDK2).

---
 .../dts/synquacer-sc2a11-developerbox-u-boot.dtsi  |    7 +
 board/socionext/developerbox/Kconfig               |   12 +
 board/socionext/developerbox/Makefile              |    1 
 board/socionext/developerbox/fwu_plat.c            |  178 ++++++++++++++++++++
 include/configs/synquacer.h                        |   10 +
 5 files changed, 207 insertions(+), 1 deletion(-)
 create mode 100644 board/socionext/developerbox/fwu_plat.c
arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi +6 -1
index 095727e03c..d2078da8b8 100644
@@ -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";
@@ -114,6 +114,11 @@
 		optee {
 			status = "okay";
 		};
+		fwu-mdata {
+			compatible = "u-boot,fwu-mdata-sf";
+			fwu-mdata-store = <&spi_flash>;
+			mdata-offsets = <0x500000 0x530000>;
+		};
 	};
 };
 
board/socionext/developerbox/Kconfig +12 -0
index c181d26a44..4120098cab 100644
@@ -32,4 +32,16 @@ config SYS_CONFIG_NAME
 	default "synquacer"
 
 endif
+
+config FWU_MULTI_BANK_UPDATE
+	select FWU_MDATA_SF
+	select DM_SPI_FLASH
+	select DM_FWU_MDATA
+
+config FWU_NUM_BANKS
+	default 6
+
+config FWU_NUM_IMAGES_PER_BANK
+	default 1
+
 endif
board/socionext/developerbox/Makefile +1 -0
index 4a46de995a..9b80ee38e7 100644
@@ -7,3 +7,4 @@
 #
 
 obj-y	:= developerbox.o
+obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu_plat.o
board/socionext/developerbox/fwu_plat.c new file +178 -0

178 lines not on this page · raw message

include/configs/synquacer.h +10 -0
index 1b6e6d011e..f00c5bb8cc 100644
@@ -51,8 +51,18 @@
 /* Since U-Boot 64bit PCIe support is limited, disable 64bit MMIO support */
 /* #define CONFIG_SYS_PCI_64BIT		1 */
 
+#ifdef CONFIG_FWU_MULTI_BANK_UPDATE
+#define DEFAULT_DFU_ALT_INFO "dfu_alt_info="				\
+				"mtd nor1=bank0 raw  600000 400000;"	\
+					 "bank1 raw  a00000 400000;"	\
+					 "bank2 raw  e00000 400000;"	\
+					 "bank3 raw 1200000 400000;"	\
+					 "bank4 raw 1600000 400000;"	\
+					 "bank5 raw 1a00000 400000\0"
+#else
 #define DEFAULT_DFU_ALT_INFO "dfu_alt_info="				\
 			"mtd nor1=fip.bin raw 600000 400000\0"
+#endif
 
 /* Distro boot settings */
 #ifndef CONFIG_SPL_BUILD
#7 lore raw

RFC PATCH v2 7/8 FWU: synquacer: Initialize broken metadata

In reply to Masami Hiramatsu

Since the FWU metadata is not initialized at the installation, if it is broken, it should be initialized. Usually, the FWU metadata is not covered by capsule update, so it is safe to initialize the metadata portion if it seems broken.

But for the production device, usually firmware will be installed with initialized metadata, and the broken metadata means the device can be compromized. In that case, build U-Boot without this option.

---
 board/socionext/developerbox/Kconfig    |   12 ++++++
 board/socionext/developerbox/fwu_plat.c |   60 +++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)
board/socionext/developerbox/Kconfig +12 -0
index 4120098cab..9fbe8d1e74 100644
@@ -44,4 +44,16 @@ config FWU_NUM_BANKS
 config FWU_NUM_IMAGES_PER_BANK
 	default 1
 
+config FWU_INIT_BROKEN_METADATA
+	bool "Initialize FWU metadata if broken"
+	select BOARD_LATE_INIT
+	default n
+	help
+	  Initialize FWU metadata if the metadata is broken.
+	  This option is only for the development environment, since if the
+	  metadata is broken, it means someone may compromize it. In that case
+	  the production device must be bricked.
+	  But for the development environment, or initial installation of the
+	  FWU multi-bank update firmware, this will be useful.
+
 endif
board/socionext/developerbox/fwu_plat.c +60 -0

63 lines not on this page · raw message

#8 lore raw

Re: [RFC PATCH v2 7/8] FWU: synquacer: Initialize broken metadata

Hi,

I decided to add tools/mkfwumdata tool to make a raw image of fwu_mdata for initialization. So this patch will be dropped from next version.

Thank you,

2022年2月18日(金) 0:12 Masami Hiramatsu <[email protected]>:

Quoted 107 lines

Since the FWU metadata is not initialized at the installation, if it is broken, it should be initialized. Usually, the FWU metadata is not covered by capsule update, so it is safe to initialize the metadata portion if it seems broken.

But for the production device, usually firmware will be installed with initialized metadata, and the broken metadata means the device can be compromized. In that case, build U-Boot without this option.

---
 board/socionext/developerbox/Kconfig    |   12 ++++++
 board/socionext/developerbox/fwu_plat.c |   60 +++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)
board/socionext/developerbox/Kconfig +12 -0
index 4120098cab..9fbe8d1e74 100644
@@ -44,4 +44,16 @@ config FWU_NUM_BANKS
 config FWU_NUM_IMAGES_PER_BANK
        default 1
 
+config FWU_INIT_BROKEN_METADATA
+       bool "Initialize FWU metadata if broken"
+       select BOARD_LATE_INIT
+       default n
+       help
+         Initialize FWU metadata if the metadata is broken.
+         This option is only for the development environment, since if the
+         metadata is broken, it means someone may compromize it. In that case
+         the production device must be bricked.
+         But for the development environment, or initial installation of the
+         FWU multi-bank update firmware, this will be useful.
+
 endif
board/socionext/developerbox/fwu_plat.c +60 -0
index cbbbd58bc0..1892f79660 100644
@@ -176,3 +176,63 @@ void fwu_plat_get_bootidx(void *boot_idx)
        else
                *bootidx = devbox_plat_metadata->boot_index;
 }
+
+#ifdef CONFIG_FWU_INIT_BROKEN_METADATA
+
+static void devbox_init_fwu_mdata(void)
+{
+       const efi_guid_t null_guid = NULL_GUID;
+       struct fwu_image_bank_info *bank;
+       struct fwu_mdata *metadata;
+       int i, j, ret;
+
+       metadata = memalign(ARCH_DMA_MINALIGN, sizeof(*metadata));
+       if (!metadata) {
+               log_err("Failed to allocate initial metadata.\n");
+               return;
+       }
+
+       metadata->version = 1;
+       metadata->active_index = 0;
+       metadata->previous_active_index = 0;
+
+       /*
+        * Since the DeveloperBox doesn't use GPT, both of
+        * fwu_image_entry::location_uuid and
+        * fwu_img_bank_info::image_uuid are null GUID.
+        */
+       for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
+               guidcpy(&metadata->img_entry[i].image_type_uuid,
+                       &devbox_fip_image_type_guid);
+               guidcpy(&metadata->img_entry[i].location_uuid,
+                       &null_guid);
+               bank = metadata->img_entry[i].img_bank_info;
+
+               for (j = 0; j < CONFIG_FWU_NUM_BANKS; j++) {
+                       guidcpy(&bank[j].image_uuid, &null_guid);
+                       bank[j].accepted = (j == 0) ? 1 : 0;
+                       bank[j].reserved = 0;
+               }
+       }
+
+       ret = fwu_update_mdata(metadata);
+       if (ret < 0)
+               log_err("Failed to initialize FWU metadata\n");
+       else
+               log_err("Initialized FWU metadata\n");
+       free(metadata);
+}
+
+int board_late_init(void)
+{
+       struct fwu_mdata *metadata;
+
+       if (fwu_get_mdata(&metadata) < 0) {
+               // Initialize FWU metadata if broken
+               log_err("Unable to get a valid metadata. Initialize it.\n");
+               devbox_init_fwu_mdata();
+       }
+       return 0;
+}
+
+#endif
Signature · 1 line
Masami Hiramatsu
#9 lore raw

RFC PATCH v2 8/8 configs: synquacer: Add FWU support for DeveloperBox

In reply to Masami Hiramatsu

Enable FWU Multi-Bank support for DeveloperBox SynQuacer platform. This also enables fwu_metadata_read command and "reboot soon after update" option.

---
 configs/synquacer_developerbox_defconfig |    7 +++++++
 1 file changed, 7 insertions(+)
configs/synquacer_developerbox_defconfig +7 -0
index 692919e1f5..3bd875c797 100644
@@ -95,3 +95,10 @@ 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_FWU_MULTI_BANK_UPDATE=y
+CONFIG_FWU_MULTI_BANK_UPDATE_SF=y
+CONFIG_FWU_MULTI_BANK_UPDATE_GPT_BLK=n
+CONFIG_CMD_FWU_METADATA=y
+CONFIG_FWU_REBOOT_AFTER_UPDATE=y
+CONFIG_FWU_INIT_BROKEN_METADATA=y