Skip to contentSkip to conversation

FWU: Add support for mtd backed feature on DeveloperBox

PATCH In review [email protected] 5 participants 14 messages May 31, 2023 – Jun 21, 2023 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

v6 cover FWU: Add support for mtd backed feature on DeveloperBox

From: Jassi Brar <[email protected]>

Introduce support for mtd backed storage for FWU feature and enable it on Synquacer platform based DeveloperBox.

This revision is rebased onto patchset that trims the FWU api
https://lore.kernel.org/u-boot/[email protected]/

Changes since v5:
* Some of the typo fixes and cosmetic changes suggested by Etienne

Changes since v4:
* Provide default/weak implementations of fwu_plat_get_alt_num and fwu_plat_get_bootidx
* Provide man page for mkfwumdata
* Misc typo fixes and cosmetic changes

Changes since v3:
* Fix and Update documentation to also build optee for FWU FIP image.
* Fixed checkpatch warnings
* Made local functions static.
* Split config changes to a separate patch
* Fix authorship of three patches.

Jassi Brar (4):
dt: fwu: developerbox: enable fwu banks and mdata regions
configs: move to new flash layout and boot flow
fwu: DeveloperBox: add support for FWU
fwu: provide default fwu_plat_get_bootidx

Masami Hiramatsu (2):
FWU: Add FWU metadata access driver for MTD storage regions
tools: Add mkfwumdata tool for FWU metadata image

 .../synquacer-sc2a11-developerbox-u-boot.dtsi |  49 ++-
 board/socionext/developerbox/Makefile         |   1 +
 board/socionext/developerbox/developerbox.c   |   8 +
 board/socionext/developerbox/fwu_plat.c       |  37 ++
 configs/synquacer_developerbox_defconfig      |  12 +-
 doc/board/socionext/developerbox.rst          | 154 +++++++-
 doc/mkfwumdata.1                              |  89 +++++
 drivers/fwu-mdata/Kconfig                     |  15 +
 drivers/fwu-mdata/Makefile                    |   1 +
 drivers/fwu-mdata/raw_mtd.c                   | 269 ++++++++++++++
 include/configs/synquacer.h                   |  10 +
 include/fwu.h                                 |  32 ++
 lib/fwu_updates/Makefile                      |   1 +
 lib/fwu_updates/fwu.c                         |  18 +
 lib/fwu_updates/fwu_mtd.c                     | 185 ++++++++++
 tools/Kconfig                                 |   9 +
 tools/Makefile                                |   4 +
 tools/mkfwumdata.c                            | 334 ++++++++++++++++++
 18 files changed, 1217 insertions(+), 11 deletions(-)
 create mode 100644 board/socionext/developerbox/fwu_plat.c
 create mode 100644 doc/mkfwumdata.1
 create mode 100644 drivers/fwu-mdata/raw_mtd.c
 create mode 100644 lib/fwu_updates/fwu_mtd.c
 create mode 100644 tools/mkfwumdata.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v6 1/6 FWU: Add FWU metadata access driver for MTD storage regions

From: Masami Hiramatsu <[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.
The code is divided into core under drivers/fwu-mdata/ and some helper functions clubbed together under lib/fwu_updates/

---
 drivers/fwu-mdata/Kconfig   |  15 ++
 drivers/fwu-mdata/Makefile  |   1 +
 drivers/fwu-mdata/raw_mtd.c | 269 ++++++++++++++++++++++++++++++++++++
 include/fwu.h               |  32 +++++
 lib/fwu_updates/Makefile    |   1 +
 lib/fwu_updates/fwu_mtd.c   | 185 +++++++++++++++++++++++++
 6 files changed, 503 insertions(+)
 create mode 100644 drivers/fwu-mdata/raw_mtd.c
 create mode 100644 lib/fwu_updates/fwu_mtd.c
drivers/fwu-mdata/Kconfig +15 -0
index 36c4479a59..42736a5e43 100644
@@ -6,6 +6,11 @@ config FWU_MDATA
 	  FWU Metadata partitions reside on the same storage device
 	  which contains the other FWU updatable firmware images.
 
+choice
+	prompt "Storage Layout Scheme"
+	depends on FWU_MDATA
+	default FWU_MDATA_GPT_BLK
+
 config FWU_MDATA_GPT_BLK
 	bool "FWU Metadata access for GPT partitioned Block devices"
 	select PARTITION_TYPE_GUID
@@ -14,3 +19,13 @@ config FWU_MDATA_GPT_BLK
 	help
 	  Enable support for accessing FWU Metadata on GPT partitioned
 	  block devices.
+
+config FWU_MDATA_MTD
+	bool "Raw MTD devices"
+	depends on MTD
+	help
+	  Enable support for accessing FWU Metadata on non-partitioned
+	  (or non-GPT partitioned, e.g. partition nodes in devicetree)
+	  MTD devices.
+
+endchoice
drivers/fwu-mdata/Makefile +1 -0
index 3fee64c10c..06c49747ba 100644
@@ -6,3 +6,4 @@
 
 obj-$(CONFIG_FWU_MDATA) += fwu-mdata-uclass.o
 obj-$(CONFIG_FWU_MDATA_GPT_BLK) += gpt_blk.o
+obj-$(CONFIG_FWU_MDATA_MTD) += raw_mtd.o
drivers/fwu-mdata/raw_mtd.c new file +269 -0

269 lines not on this page · raw message

include/fwu.h +32 -0
index 33b4d0b3db..edb7e9da90 100644
@@ -8,6 +8,8 @@
 
 #include <blk.h>
 #include <efi.h>
+#include <mtd.h>
+#include <uuid.h>
 
 #include <linux/types.h>
 
@@ -18,6 +20,12 @@ struct fwu_mdata_gpt_blk_priv {
 	struct udevice *blk_dev;
 };
 
+struct fwu_mtd_image_info {
+	u32 start, size;
+	int bank_num, image_num;
+	char uuidbuf[UUID_STR_LEN + 1];
+};
+
 struct fwu_mdata_ops {
 	/**
 	 * read_mdata() - Populate the asked FWU metadata copy
@@ -251,4 +259,28 @@ u8 fwu_empty_capsule_checks_pass(void);
  */
 int fwu_trial_state_ctr_start(void);
 
+/**
+ * fwu_gen_alt_info_from_mtd() - Parse dfu_alt_info from metadata in mtd
+ * @buf: Buffer into which the dfu_alt_info is filled
+ * @len: Maximum characters that can be written in buf
+ * @mtd: Pointer to underlying MTD device
+ *
+ * Parse dfu_alt_info from metadata in mtd. Used for setting the env.
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int fwu_gen_alt_info_from_mtd(char *buf, size_t len, struct mtd_info *mtd);
+
+/**
+ * fwu_mtd_get_alt_num() - Mapping of fwu_plat_get_alt_num for MTD device
+ * @image_guid: Image GUID for which DFU alt number needs to be retrieved
+ * @alt_num: Pointer to the alt_num
+ * @mtd_dev: Name of mtd device instance
+ *
+ * To map fwu_plat_get_alt_num onto mtd based metadata implementation.
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int fwu_mtd_get_alt_num(efi_guid_t *image_guid, u8 *alt_num, const char *mtd_dev);
+
 #endif /* _FWU_H_ */
lib/fwu_updates/Makefile +1 -0
index 1993088e5b..c9e3c06b48 100644
@@ -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 +185 -0

185 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

PATCH v6 2/6 tools: Add mkfwumdata tool for FWU metadata image

In reply to [email protected]

From: Masami Hiramatsu <[email protected]>

Add 'mkfwumdata' tool to generate FWU metadata image for the meta-data partition to be used in A/B Update imeplementation.

---
 doc/mkfwumdata.1   |  89 ++++++++++++
 tools/Kconfig      |   9 ++
 tools/Makefile     |   4 +
 tools/mkfwumdata.c | 334 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 436 insertions(+)
 create mode 100644 doc/mkfwumdata.1
 create mode 100644 tools/mkfwumdata.c
doc/mkfwumdata.1 new file +89 -0
new file mode 100644
index 0000000000..7dd718b26e
@@ -0,0 +1,89 @@
+.\" SPDX-License-Identifier: GPL-2.0-or-later
+.\" Copyright (C) 2023 Jassi Brar <[email protected]>
+.TH MKFWUMDATA 1 2023-04-10 U-Boot
+.SH NAME
+mkfwumdata \- create FWU metadata image
+.
+.SH SYNOPSIS
+.SY mkfwumdata
+.OP \-a activeidx
+.OP \-p previousidx
+.OP \-g
+.BI \-i\~ imagecount
+.BI \-b\~ bankcount
+.I UUIDs
+.I outputimage
+.YS
+.SY mkfwumdata
+.B \-h
+.YS
+.
+.SH DESCRIPTION
+.B mkfwumdata
+creates metadata info to be used with FWU.
+.
+.SH OPTIONS
+.TP
+.B \-h
+Print usage information and exit.
+.
+.TP
+.B \-a
+Set 
+.IR activeidx
+as the currently active Bank. Default is 0.
+.
+.TP
+.B \-p
+Set 
+.IR previousidx
+as the previous active Bank. Default is
+.IR activeidx "-1"
+or
+.IR bankcount "-1,"
+whichever is non-negative.
+.
+.TP
+.B \-g
+Convert the
+.IR UUIDs
+as GUIDs before use.
+.
+.TP
+.B \-i
+Specify there are
+.IR imagecount
+images in each bank.
+.
+.TP
+.B \-b
+Specify there are a total of
+.IR bankcount
+banks.
+.
+.TP
+.IR UUIDs
+Comma-separated list of UUIDs required to create the metadata :-
+location_uuid,image_type_uuid,<images per bank uuid list of all banks>
+.
+.TP
+.IR outputimage
+Specify the name of the metadata image file to be created.
+.
+.SH BUGS
+Please report bugs to the
+.UR https://\:source\:.denx\:.de/\:u-boot/\:u-boot/\:issues
+U-Boot bug tracker
+.UE .
+.SH EXAMPLES
+Create a metadata image with 2 banks and 1 image/bank, BankAct=0, BankPrev=1:
+.PP
+.EX
+.in +4
+$ \c
+.B mkfwumdata \-a 0 \-p 1 \-b 2 \-i 1 \\\\\&
+.in +6
+.B 17e86d77-41f9-4fd7-87ec-a55df9842de5,\\\\\&
+.B 10c36d7d-ca52-b843-b7b9-f9d6c501d108,\\\\\&
+.B 5a66a702-99fd-4fef-a392-c26e261a2828,a8f868a1-6e5c-4757-878d-ce63375ef2c0 \\\\\&
+.B fwu-mdata.img
tools/Kconfig +9 -0
index 539708f277..6e23f44d55 100644
@@ -157,4 +157,13 @@ config LUT_SEQUENCE
 	help
 	  Look Up Table Sequence
 
+config TOOLS_MKFWUMDATA
+	bool "Build mkfwumdata command"
+	default y if FWU_MULTI_BANK_UPDATE
+	help
+	  This command allows users to create a raw image of the FWU
+	  metadata for initial installation of the FWU multi bank
+	  update on the board. The installation method depends on
+	  the platform.
+
 endmenu
tools/Makefile +4 -0
index d793cf3bec..a0cd87ff93 100644
@@ -251,6 +251,10 @@ HOSTLDLIBS_mkeficapsule += \
 	$(shell pkg-config --libs uuid 2> /dev/null || echo "-luuid")
 hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule
 
+mkfwumdata-objs := mkfwumdata.o lib/crc32.o
+HOSTLDLIBS_mkfwumdata += -luuid
+hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata
+
 # We build some files with extra pedantic flags to try to minimize things
 # that won't build on some weird host compiler -- though there are lots of
 # exceptions for files that aren't complaint.
tools/mkfwumdata.c new file +334 -0

334 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

PATCH v6 3/6 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 | 49 +++++++++++++++++--
 1 file changed, 46 insertions(+), 3 deletions(-)
arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi +46 -3
index 9f9837b33b..9957646a46 100644
@@ -21,7 +21,7 @@
 		#size-cells = <0>;
 		status = "okay";
 
-		flash@0 {
+		flash0: flash@0 {
 			#address-cells = <1>;
 			#size-cells = <1>;
 			compatible = "jedec,spi-nor";
@@ -74,8 +74,24 @@
 				};
 
 				partition@500000 {
-					label = "Ex-OPTEE";
-					reg = <0x500000 0x200000>;
+					label = "MDATA-Pri";
+					reg = <0x500000 0x1000>;
+				};
+
+				partition@530000 {
+					label = "MDATA-Sec";
+					reg = <0x530000 0x1000>;
+				};
+
+				/* FWU Multi bank update partitions */
+				partition@600000 {
+					label = "FIP-Bank0";
+					reg = <0x600000 0x400000>;
+				};
+
+				partition@a00000 {
+					label = "FIP-Bank1";
+					reg = <0xa00000 0x400000>;
 				};
 			};
 		};
@@ -102,6 +118,33 @@
 		optee {
 			status = "okay";
 		};
+
+		fwu-mdata {
+			compatible = "u-boot,fwu-mdata-mtd";
+			fwu-mdata-store = <&flash0>;
+			mdata-parts = "MDATA-Pri", "MDATA-Sec";
+
+			fwu-bank0 {
+				id = <0>;
+				label = "FIP-Bank0";
+				fwu-image0 {
+					id = <0>;
+					offset = <0x0>;
+					size = <0x400000>;
+					uuid = "5a66a702-99fd-4fef-a392-c26e261a2828";
+				};
+			};
+			fwu-bank1 {
+				id = <1>;
+				label = "FIP-Bank1";
+				fwu-image0 {
+					id = <0>;
+					offset = <0x0>;
+					size = <0x400000>;
+					uuid = "a8f868a1-6e5c-4757-878d-ce63375ef2c0";
+				};
+			};
+		};
 	};
 };
 
Signature · 1 line
2.34.1
#4 lore raw

PATCH v6 4/6 config: developerbox: move to new flash layout and boot flow

In reply to [email protected]

From: Jassi Brar <[email protected]>

Towards enabling FWU and supporting new firmware layout in NOR flash, make u-boot PIC and adjust uboot env offset in flash.

---
 configs/synquacer_developerbox_defconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configs/synquacer_developerbox_defconfig +2 -2
index 68f7bacf02..0c37897c9a 100644
@@ -1,13 +1,13 @@
 CONFIG_ARM=y
 CONFIG_ARCH_SYNQUACER=y
-CONFIG_TEXT_BASE=0x08200000
+CONFIG_POSITION_INDEPENDENT=y
 CONFIG_SYS_MALLOC_LEN=0x1000000
 CONFIG_SYS_MALLOC_F_LEN=0x400
 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xe0000000
 CONFIG_SF_DEFAULT_SPEED=31250000
 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"
Signature · 1 line
2.34.1
#5 lore raw

PATCH v6 5/6 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 |   8 +
 board/socionext/developerbox/fwu_plat.c     |  37 +++++
 configs/synquacer_developerbox_defconfig    |   8 +
 doc/board/socionext/developerbox.rst        | 154 +++++++++++++++++++-
 include/configs/synquacer.h                 |  10 ++
 6 files changed, 212 insertions(+), 6 deletions(-)
 create mode 100644 board/socionext/developerbox/fwu_plat.c
board/socionext/developerbox/Makefile +1 -0
index 4a46de995a..1acd067a7e 100644
@@ -7,3 +7,4 @@
 #
 
 obj-y	:= developerbox.o
+obj-$(CONFIG_FWU_MDATA_MTD) += fwu_plat.o
board/socionext/developerbox/developerbox.c +8 -0
index 16e14d4f7f..ce2cccf4f0 100644
@@ -20,6 +20,13 @@
 
 #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
 struct efi_fw_image fw_images[] = {
+#if CONFIG_IS_ENABLED(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,6 +42,7 @@ struct efi_fw_image fw_images[] = {
 		.fw_name = u"DEVELOPERBOX-OPTEE",
 		.image_index = 3,
 	},
+#endif
 };
 
 struct efi_capsule_update_info update_info = {
board/socionext/developerbox/fwu_plat.c new file +37 -0
new file mode 100644
index 0000000000..e724e702bd
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023, Linaro Limited
+ */
+
+#include <efi_loader.h>
+#include <fwu.h>
+#include <fwu_mdata.h>
+#include <memalign.h>
+#include <mtd.h>
+
+#define DFU_ALT_BUF_LEN 256
+
+/* Generate dfu_alt_info from partitions */
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+	struct mtd_info *mtd;
+	int ret;
+
+	memset(buf, 0, sizeof(buf));
+
+	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);
+}
configs/synquacer_developerbox_defconfig +8 -0
index 0c37897c9a..8e7236b572 100644
@@ -97,3 +97,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_FWU_MULTI_BANK_UPDATE=y
+CONFIG_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
+CONFIG_TOOLS_MKFWUMDATA=y
doc/board/socionext/developerbox.rst +148 -6

169 lines not on this page · raw message

include/configs/synquacer.h +10 -0
index 8f44c6f66a..cd7359c2f8 100644
@@ -40,19 +40,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.34.1
#6 lore raw

PATCH v6 6/6 fwu: provide default fwu_plat_get_bootidx

In reply to [email protected]

From: Jassi Brar <[email protected]>

Just like fwu_plat_get_update_index, provide a default/weak implementation of fwu_plat_get_bootidx. So that most platforms wouldn't have to re-implement the likely case.

---
 lib/fwu_updates/fwu.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
lib/fwu_updates/fwu.c +18 -0
index a24ccf567a..c9996f4d6d 100644
@@ -545,6 +545,24 @@ __weak int fwu_plat_get_update_index(uint *update_idx)
 	return ret;
 }
 
+/**
+ * fwu_plat_get_bootidx() - Get the value of the boot index
+ * @boot_idx: Boot index value
+ *
+ * Get the value of the bank(partition) from which the platform
+ * has booted. This value is passed to U-Boot from the earlier
+ * stage bootloader which loads and boots all the relevant
+ * firmware images
+ */
+__weak void fwu_plat_get_bootidx(uint *boot_idx)
+{
+	int ret;
+
+	ret = fwu_get_active_index(boot_idx);
+	if (ret < 0)
+		*boot_idx = 0; /* Dummy value */
+}
+
 /**
  * fwu_update_checks_pass() - Check if FWU update can be done
  *
Signature · 1 line
2.34.1
#8 lore raw
In reply to [email protected]

Hi Jassi,

Quoted 53 lines · On 5/31/23 07:28, [email protected] wrote:

From: Jassi Brar <[email protected]>

Introduce support for mtd backed storage for FWU feature and enable it on Synquacer platform based DeveloperBox.

This revision is rebased onto patchset that trims the FWU api
https://lore.kernel.org/u-boot/[email protected]/

Changes since v5:
* Some of the typo fixes and cosmetic changes suggested by Etienne

Changes since v4:
* Provide default/weak implementations of fwu_plat_get_alt_num and fwu_plat_get_bootidx
* Provide man page for mkfwumdata
* Misc typo fixes and cosmetic changes

Changes since v3:
* Fix and Update documentation to also build optee for FWU FIP image.
* Fixed checkpatch warnings
* Made local functions static.
* Split config changes to a separate patch
* Fix authorship of three patches.

Jassi Brar (4):
dt: fwu: developerbox: enable fwu banks and mdata regions
configs: move to new flash layout and boot flow
fwu: DeveloperBox: add support for FWU
fwu: provide default fwu_plat_get_bootidx

Masami Hiramatsu (2):
FWU: Add FWU metadata access driver for MTD storage regions
tools: Add mkfwumdata tool for FWU metadata image

  .../synquacer-sc2a11-developerbox-u-boot.dtsi |  49 ++-
  board/socionext/developerbox/Makefile         |   1 +
  board/socionext/developerbox/developerbox.c   |   8 +
  board/socionext/developerbox/fwu_plat.c       |  37 ++
  configs/synquacer_developerbox_defconfig      |  12 +-
  doc/board/socionext/developerbox.rst          | 154 +++++++-
  doc/mkfwumdata.1                              |  89 +++++
  drivers/fwu-mdata/Kconfig                     |  15 +
  drivers/fwu-mdata/Makefile                    |   1 +
  drivers/fwu-mdata/raw_mtd.c                   | 269 ++++++++++++++
  include/configs/synquacer.h                   |  10 +
  include/fwu.h                                 |  32 ++
  lib/fwu_updates/Makefile                      |   1 +
  lib/fwu_updates/fwu.c                         |  18 +
  lib/fwu_updates/fwu_mtd.c                     | 185 ++++++++++
  tools/Kconfig                                 |   9 +
  tools/Makefile                                |   4 +
  tools/mkfwumdata.c                            | 334 ++++++++++++++++++
  18 files changed, 1217 insertions(+), 11 deletions(-)
Quoted 6 lines

create mode 100644 board/socionext/developerbox/fwu_plat.c create mode 100644 doc/mkfwumdata.1
create mode 100644 drivers/fwu-mdata/raw_mtd.c create mode 100644 lib/fwu_updates/fwu_mtd.c create mode 100644 tools/mkfwumdata.c

I know that Tom has applied this already but I still think there is a work to do here.
Firstly I can generate 2 images per one bank which should be pretty much regular capsule update for 2 images. I would expect this should still work.

And then I tried 2 banks with 2 images and fwu_gen_alt_info_from_mtd() generated this description for DFU

mtd nor0=bank0 raw 2320000 80000;bank1 raw 27a0000 8000&mtd nor0=bank0 raw 23a0000 4000000;bank1 raw 2820000 4000000

If you look at size in second entry you will see that it is 8000 instead of 80000 because it is the same image. That's why curious if you have tested any scenario like this.

Next part which I want to take a look is practicality of CONFIG_FWU_NUM_BANKS and CONFIG_FWU_NUM_IMAGES_PER_BANK because it pretty much enforcing number of banks and images for every platform and prevent creating one u-boot which works on different boards and just use information from mdata. DEN0118 doesn't show any field with this information but do you think that would be possible to extract that information from there based on for example reserved or accepted field?

Thanks,
Michal

author
#9 lore raw

Hi Michal,

Quoted 12 lines · Michal Simek

Hi Jassi,

Quoted 8 lines · On 5/31/23 07:28, [email protected] wrote:

From: Jassi Brar <[email protected]>

Introduce support for mtd backed storage for FWU feature and enable it on Synquacer platform based DeveloperBox.

This revision is rebased onto patchset that trims the FWU api
https://lore.kernel.org/u-boot/[email protected]/

.....

Quoted 6 lines

Firstly I can generate 2 images per one bank which should be pretty much regular capsule update for 2 images. I would expect this should still work.

And then I tried 2 banks with 2 images and fwu_gen_alt_info_from_mtd() generated this description for DFU

Quoted 7 lines

mtd nor0=bank0 raw 2320000 80000;bank1 raw 27a0000 8000&mtd nor0=bank0 raw 23a0000 4000000;bank1 raw 2820000 4000000

If you look at size in second entry you will see that it is 8000 instead of 80000 because it is the same image. That's why curious if you have tested any scenario like this.

I had, and have, strong doubts about the practicality of 2 images/bank. There aren't enough specification details to explain how only 1-out-of-N images could be updated. And if we always update all images in a bank together, we might as well have them as one composite image. I never got satisfactory clarification from designers and implementers. So, sorry, I can't defend that scenario with my limited knowledge.

Quoted 8 lines

Next part which I want to take a look is practicality of CONFIG_FWU_NUM_BANKS and CONFIG_FWU_NUM_IMAGES_PER_BANK because it pretty much enforcing number of banks and images for every platform and prevent creating one u-boot which works on different boards and just use information from mdata.
DEN0118 doesn't show any field with this information but do you think that would be possible to extract that information from there based on for example reserved or accepted field?

Unfortunately the DEN0118 spec doesn't leave any 'don't care' bits in 'accepted' or 'reserved' fields, all unused bits Must-Be-Zero. If we use any bit, we'll be in violation of the spec.

However, we can do CRC32 calculations by varying NUM_IMAGES_PER_BANK and NUM_BANKS and find the value pair for which the crc32 field matches!
For limiting check-loops and finding corrupted metadata, the .config can carry upper limits on both the options, say MAX_NUM_IMAGES_PER_BANK=5 and MAX_NUM_BANKS=10 for the most special scenario. If we find the approach acceptable, I can cook a patch as proof-of-concept.

cheers.

#10 lore raw

Sorry for being late to the party,

+cc Jose who maintains DEN0118

Quoted 30 lines · Jassi Brar

Hi Michal,

Quoted 12 lines · Michal Simek

Hi Jassi,

Quoted 8 lines · On 5/31/23 07:28, [email protected] wrote:

From: Jassi Brar <[email protected]>

Introduce support for mtd backed storage for FWU feature and enable it on Synquacer platform based DeveloperBox.

This revision is rebased onto patchset that trims the FWU api
https://lore.kernel.org/u-boot/[email protected]/

.....

Quoted 6 lines

Firstly I can generate 2 images per one bank which should be pretty much regular capsule update for 2 images. I would expect this should still work.

And then I tried 2 banks with 2 images and fwu_gen_alt_info_from_mtd() generated this description for DFU

Quoted 7 lines

mtd nor0=bank0 raw 2320000 80000;bank1 raw 27a0000 8000&mtd nor0=bank0 raw 23a0000 4000000;bank1 raw 2820000 4000000

If you look at size in second entry you will see that it is 8000 instead of 80000 because it is the same image. That's why curious if you have tested any scenario like this.

Quoted 7 lines

I had, and have, strong doubts about the practicality of 2 images/bank. There aren't enough specification details to explain how only 1-out-of-N images could be updated. And if we always update all images in a bank together, we might as well have them as one composite image. I never got satisfactory clarification from designers and implementers. So, sorry, I can't defend that scenario with my limited knowledge.

This is intentionally left out, as we consider it a platform policy. For example you could update a single bank and copy over the remaining firmware images from a different ban. There's nothing on the spec that prohibits you from doing so, but I personally think it's a bad idea. Keep in mind there's a document hosted here[0] which explains the update flow and documents what we have as code in U-Boot.

As far as individual firmware components go now, do you have any useful usecase? The general guidance of [0] is construct a firmware image, only update the components you want while leaving the rest on the same revisions and update the entire firmware. The reason is that firmware

Updating a single image of another bank is not as easy as it sounds. Firmware components nowadays, whether we like it or not, depend on each other. Since firmware updates are not so often and fast, we didn't see any gains from over complicating the spec and explicitly describe that case, while dealing with firmware component compatibility at the same time.

Quoted 9 lines
Quoted 9 lines

Next part which I want to take a look is practicality of CONFIG_FWU_NUM_BANKS and CONFIG_FWU_NUM_IMAGES_PER_BANK because it pretty much enforcing number of banks and images for every platform and prevent creating one u-boot which works on different boards and just use information from mdata.
DEN0118 doesn't show any field with this information but do you think that would be possible to extract that information from there based on for example reserved or accepted field?

Quoted 3 lines

Unfortunately the DEN0118 spec doesn't leave any 'don't care' bits in 'accepted' or 'reserved' fields, all unused bits Must-Be-Zero. If we use any bit, we'll be in violation of the spec.

Yes this is unfortunate. We did have similar concerns on when drafting the spec, however we never had a solid usecase to justify this. Arm and Linaro and working on a v2 (which we try to make compatible with v1) which addresses this shortcoming. Maybe Jose can chime in.

Quoted 11 lines

However, we can do CRC32 calculations by varying NUM_IMAGES_PER_BANK and NUM_BANKS and find the value pair for which the crc32 field matches!
For limiting check-loops and finding corrupted metadata, the .config can carry upper limits on both the options, say MAX_NUM_IMAGES_PER_BANK=5 and MAX_NUM_BANKS=10 for the most special scenario. If we find the approach acceptable, I can cook a patch as proof-of-concept.

cheers.

[0] https://gitlab.com/Linaro/trustedsubstrate/mbfw/uploads/3d0d7d11ca9874dc9115616b418aa330/mbfw.pdf

Thanks
/Ilias

author
#11 lore raw
Quoted 44 lines · Ilias Apalodimas

Sorry for being late to the party,

+cc Jose who maintains DEN0118

Quoted 30 lines · Jassi Brar

Hi Michal,

Quoted 12 lines · Michal Simek

Hi Jassi,

Quoted 8 lines · On 5/31/23 07:28, [email protected] wrote:

From: Jassi Brar <[email protected]>

Introduce support for mtd backed storage for FWU feature and enable it on Synquacer platform based DeveloperBox.

This revision is rebased onto patchset that trims the FWU api
https://lore.kernel.org/u-boot/[email protected]/

.....

Quoted 6 lines

Firstly I can generate 2 images per one bank which should be pretty much regular capsule update for 2 images. I would expect this should still work.

And then I tried 2 banks with 2 images and fwu_gen_alt_info_from_mtd() generated this description for DFU

Quoted 7 lines

mtd nor0=bank0 raw 2320000 80000;bank1 raw 27a0000 8000&mtd nor0=bank0 raw 23a0000 4000000;bank1 raw 2820000 4000000

If you look at size in second entry you will see that it is 8000 instead of 80000 because it is the same image. That's why curious if you have tested any scenario like this.

Quoted 7 lines

I had, and have, strong doubts about the practicality of 2 images/bank. There aren't enough specification details to explain how only 1-out-of-N images could be updated. And if we always update all images in a bank together, we might as well have them as one composite image. I never got satisfactory clarification from designers and implementers. So, sorry, I can't defend that scenario with my limited knowledge.

Quoted 5 lines

This is intentionally left out, as we consider it a platform policy. For example you could update a single bank and copy over the remaining firmware images from a different ban. There's nothing on the spec that prohibits you from doing so, but I personally think it's a bad idea.

Me too.

Quoted 6 lines

Keep in mind there's a document hosted here[0] which explains the update flow and documents what we have as code in U-Boot.

As far as individual firmware components go now, do you have any useful usecase?

No. And I don't think current A/B update implementation in u-boot even has helpers for platforms to implement multiple images per bank. Which is fine, except we pretend we do by having NUM_IMAGES_PER_BANK config -- which will always be set to 1 I predict ;)

Quoted 6 lines

The general guidance of [0] is construct a firmware
image, only update the components you want while leaving the rest on the same revisions and update the entire firmware. The reason is that firmware

Updating a single image of another bank is not as easy as it sounds.

exactly.

Quoted 5 lines

Firmware components nowadays, whether we like it or not, depend on each other. Since firmware updates are not so often and fast, we didn't see any gains from over complicating the spec and explicitly describe that case, while dealing with firmware component compatibility at the same time.

Totally. As I said, I don't believe in the practicality of more than 1 image/bank.
So we are on the same page.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Next part which I want to take a look is practicality of CONFIG_FWU_NUM_BANKS and CONFIG_FWU_NUM_IMAGES_PER_BANK because it pretty much enforcing number of banks and images for every platform and prevent creating one u-boot which works on different boards and just use information from mdata.
DEN0118 doesn't show any field with this information but do you think that would be possible to extract that information from there based on for example reserved or accepted field?

Quoted 9 lines
Quoted 3 lines

Unfortunately the DEN0118 spec doesn't leave any 'don't care' bits in 'accepted' or 'reserved' fields, all unused bits Must-Be-Zero. If we use any bit, we'll be in violation of the spec.

Yes this is unfortunate. We did have similar concerns on when drafting the spec, however we never had a solid usecase to justify this. Arm and Linaro and working on a v2 (which we try to make compatible with v1) which addresses this shortcoming. Maybe Jose can chime in.

OK. If we have, say, reserved[0] as last Image and reserved[1] as last Bank, we could get rid of the two compile-time configs.

Thanks.

#12 lore raw
Quoted 56 lines · Jassi Brar
Quoted 44 lines · Ilias Apalodimas

Sorry for being late to the party,

+cc Jose who maintains DEN0118

Quoted 30 lines · Jassi Brar

Hi Michal,

Quoted 12 lines · Michal Simek

Hi Jassi,

Quoted 8 lines · On 5/31/23 07:28, [email protected] wrote:

From: Jassi Brar <[email protected]>

Introduce support for mtd backed storage for FWU feature and enable it on Synquacer platform based DeveloperBox.

This revision is rebased onto patchset that trims the FWU api
https://lore.kernel.org/u-boot/[email protected]/

.....

Quoted 6 lines

Firstly I can generate 2 images per one bank which should be pretty much regular capsule update for 2 images. I would expect this should still work.

And then I tried 2 banks with 2 images and fwu_gen_alt_info_from_mtd() generated this description for DFU

Quoted 7 lines

mtd nor0=bank0 raw 2320000 80000;bank1 raw 27a0000 8000&mtd nor0=bank0 raw 23a0000 4000000;bank1 raw 2820000 4000000

If you look at size in second entry you will see that it is 8000 instead of 80000 because it is the same image. That's why curious if you have tested any scenario like this.

Quoted 7 lines

I had, and have, strong doubts about the practicality of 2 images/bank. There aren't enough specification details to explain how only 1-out-of-N images could be updated. And if we always update all images in a bank together, we might as well have them as one composite image. I never got satisfactory clarification from designers and implementers. So, sorry, I can't defend that scenario with my limited knowledge.

Quoted 5 lines

This is intentionally left out, as we consider it a platform policy. For example you could update a single bank and copy over the remaining firmware images from a different ban. There's nothing on the spec that prohibits you from doing so, but I personally think it's a bad idea.

Me too.

Quoted 3 lines

Keep in mind there's a document hosted here[0] which explains the update flow and documents what we have as code in U-Boot.

Quoted 7 lines
Quoted 3 lines

As far as individual firmware components go now, do you have any useful usecase?

No. And I don't think current A/B update implementation in u-boot even has helpers for platforms to implement multiple images per bank. Which is fine, except we pretend we do by having NUM_IMAGES_PER_BANK config -- which will always be set to 1 I predict ;)

Actually support is there but it requires one thing to patch. I will send that patch when I clean my repo. And I have tested it on our platform.

Quoted 9 lines
Quoted 7 lines

The general guidance of [0] is construct a firmware
image, only update the components you want while leaving the rest on the same revisions and update the entire firmware. The reason is that firmware

Updating a single image of another bank is not as easy as it sounds.

exactly.

Quoted 27 lines
Quoted 5 lines

Firmware components nowadays, whether we like it or not, depend on each other. Since firmware updates are not so often and fast, we didn't see any gains from over complicating the spec and explicitly describe that case, while dealing with firmware component compatibility at the same time.

Totally. As I said, I don't believe in the practicality of more than 1 image/bank.
So we are on the same page.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

Next part which I want to take a look is practicality of CONFIG_FWU_NUM_BANKS and CONFIG_FWU_NUM_IMAGES_PER_BANK because it pretty much enforcing number of banks and images for every platform and prevent creating one u-boot which works on different boards and just use information from mdata.
DEN0118 doesn't show any field with this information but do you think that would be possible to extract that information from there based on for example reserved or accepted field?

Quoted 3 lines

Unfortunately the DEN0118 spec doesn't leave any 'don't care' bits in 'accepted' or 'reserved' fields, all unused bits Must-Be-Zero. If we use any bit, we'll be in violation of the spec.

Yes this is unfortunate. We did have similar concerns on when drafting the spec, however we never had a solid usecase to justify this. Arm and Linaro and working on a v2 (which we try to make compatible with v1) which addresses this shortcoming. Maybe Jose can chime in.

Another way would be to simply decode this information directly from DT fwu-mdata node. Because from that node it is clear how many banks and how many images that particular bank has.

Thanks,
Michal

#13 lore raw

Hi,

Quoted 130 lines

-----Original Message-----
From: Michal Simek <[email protected]>
Sent: Tuesday, June 20, 2023 3:20 PM
To: Jassi Brar <[email protected]>; Ilias Apalodimas <[email protected]>
Cc: Jose Marinho <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 0/6] FWU: Add support for mtd backed feature on DeveloperBox

Quoted 11 lines · Jassi Brar
Quoted 9 lines · Ilias Apalodimas

Sorry for being late to the party,

+cc Jose who maintains DEN0118

Quoted 3 lines · Jassi Brar

Hi Michal,

On Mon, 19 Jun 2023 at 10:02, Michal Simek <[email protected]>

Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hi Jassi,

On 5/31/23 07:28, [email protected] wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Jassi Brar <[email protected]>

Introduce support for mtd backed storage for FWU feature and enable it on Synquacer platform based DeveloperBox.

This revision is rebased onto patchset that trims the FWU api

https://lore.kernel.org/u-boot/20230306231747.1888513-1-

jassisingh

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

[email protected]/

.....

Quoted 2 lines

Firstly I can generate 2 images per one bank which should be pretty much regular capsule update for 2 images. I would expect this should still

work.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 4 lines

And then I tried 2 banks with 2 images and fwu_gen_alt_info_from_mtd() generated this description for DFU

Quoted 9 lines

mtd nor0=bank0 raw 2320000 80000;bank1 raw 27a0000 8000&mtd nor0=bank0 raw
23a0000 4000000;bank1 raw 2820000 4000000

If you look at size in second entry you will see that it is 8000 instead of
80000 because it is the same image. That's why curious if you have tested any scenario like this.

I had, and have, strong doubts about the practicality of 2 images/bank. There aren't enough specification details to explain how only 1-out-of-N images could be updated. And if we always update all images in a bank together, we might as well have them as one composite image. I never got satisfactory clarification from designers and implementers. So, sorry, I can't defend that scenario with my limited knowledge.

Quoted 4 lines
Quoted 4 lines

This is intentionally left out, as we consider it a platform policy. For example you could update a single bank and copy over the remaining firmware images from a different ban. There's nothing on the spec that prohibits you from doing so, but I personally think it's a bad

idea.

Quoted 6 lines
Quoted 1 line

Me too.

Quoted 3 lines

Keep in mind there's a document hosted here[0] which explains the update flow and documents what we have as code in U-Boot.

Quoted 7 lines
Quoted 3 lines

As far as individual firmware components go now, do you have any useful usecase?

No. And I don't think current A/B update implementation in u-boot even has helpers for platforms to implement multiple images per bank. Which is fine, except we pretend we do by having NUM_IMAGES_PER_BANK config -- which will always be set to 1 I predict ;)

Actually support is there but it requires one thing to patch. I will send that patch when I clean my repo.
And I have tested it on our platform.

Quoted 11 lines
Quoted 8 lines

The general guidance of [0] is construct a firmware image, only
update the components you want while leaving the rest on the same revisions and update the entire firmware. The reason is that firmware

Updating a single image of another bank is not as easy as it sounds.

exactly.

Quoted 1 line

Firmware components nowadays, whether we like it or not, depend on

each other.

Quoted 3 lines
Quoted 3 lines

Since firmware updates are not so often and fast, we didn't see any gains from over complicating the spec and explicitly describe that case, while dealing with firmware component compatibility at the same

time.

Quoted 8 lines
Quoted 1 line

Totally. As I said, I don't believe in the practicality of more than 1 image/bank.
So we are on the same page.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Next part which I want to take a look is practicality of CONFIG_FWU_NUM_BANKS and

CONFIG_FWU_NUM_IMAGES_PER_BANK because it

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

pretty much enforcing number of banks and images for every platform and prevent creating one u-boot which works on different boards and

just use information from mdata.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

DEN0118 doesn't show any field with this information but do you think that would be possible to extract that information from there based on for example reserved or accepted field?

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Unfortunately the DEN0118 spec doesn't leave any 'don't care' bits in 'accepted' or 'reserved' fields, all unused bits Must-Be-Zero. If we use any bit, we'll be in violation of the spec.

Yes this is unfortunate. We did have similar concerns on when drafting the spec, however we never had a solid usecase to justify this. Arm and Linaro and working on a v2 (which we try to make compatible with v1) which addresses this shortcoming. Maybe Jose can

Quoted 7 lines

chime in.

Quoted 1 line
Quoted 1 line

Another way would be to simply decode this information directly from DT fwu-mdata node. Because from that node it is clear how many banks and how many images that particular bank has.

The FW update document (DEN0118) is in the process of being released.
It defines the v2 of the metadata data-structure.
Version 2 should better fit the deployment models since it has a field for 'number of banks' and another for 'number of images per bank'. Happy to discuss in general, and in particular if we find any gaps 😊!

Regards,
Jose

Quoted 3 lines

Thanks,
Michal