Skip to contentSkip to conversation

Add dumpfwumdata tool for FWU metadata image

PATCH In review Dario Binacchi 3 participants 13 messages Dec 28, 2025 – Jan 19

lore
Share & tools
lore
#0 lore raw

cover Add dumpfwumdata tool for FWU metadata image

This series originates from the implementation of the A/B update scheme on a custom board based on the STM32MP2 platform. The addition of the dumpfwumdata tool required changes to its counterpart mkfwumdata in order to ensure code consistency and readability.
Finally, I considered it useful to enable both tools in the tools-only configuration.

Dario Binacchi (5):
tools: build mkfwumdata with tools-only_defconfig
fwu: centralize bank state macros in fwu_mdata.h
fwu: use FWU_MAX_STATE_BANKS for bank_state array
tools: Add dumpfwumdata tool for FWU metadata image
tools: build dumpfwumdata with tools-only_defconfig

 configs/tools-only_defconfig |   2 +
 include/fwu.h                |   4 --
 include/fwu_mdata.h          |   9 ++-
 tools/Kconfig                |   7 ++
 tools/Makefile               |   4 ++
 tools/dumpfwumdata.c         | 128 +++++++++++++++++++++++++++++++++++
 tools/mkfwumdata.c           |  10 +--
 7 files changed, 151 insertions(+), 13 deletions(-)
 create mode 100644 tools/dumpfwumdata.c
Signature · 4 lines
2.43.0

base-commit: 56cac250b0839ddbad1311d3ca4231f532b5aadf
branch: fwumdata
#1 lore raw

PATCH 1/5 tools: build mkfwumdata with tools-only_defconfig

Always build mkfwumdata when using tools-only_defconfig.

---

 configs/tools-only_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/tools-only_defconfig +1 -0
index 42ec59575100..bdc646e29b32 100644
@@ -40,3 +40,4 @@ CONFIG_VIRTIO_PCI=n
 CONFIG_VIRTIO_SANDBOX=n
 CONFIG_GENERATE_ACPI_TABLE=n
 CONFIG_TOOLS_MKEFICAPSULE=y
+CONFIG_TOOLS_MKFWUMDATA=y
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/5 fwu: centralize bank state macros in fwu_mdata.h

In reply to Dario Binacchi

Move the bank state definitions to fwu_mdata.h so they live next to the structures they describe and can be consistently reused by both U-Boot code and mkfwumdata, avoiding duplication and reducing the risk of mismatched constants.

---

 include/fwu.h       | 4 ----
 include/fwu_mdata.h | 4 ++++
 tools/mkfwumdata.c  | 5 +----
 3 files changed, 5 insertions(+), 8 deletions(-)
include/fwu.h +0 -4
index e7bd1d492af1..c9549019601c 100644
@@ -80,10 +80,6 @@ struct fwu_mdata_ops {
 
 #define FWU_IMAGE_ACCEPTED	0x1
 
-#define FWU_BANK_INVALID	(uint8_t)0xFF
-#define FWU_BANK_VALID		(uint8_t)0xFE
-#define FWU_BANK_ACCEPTED	(uint8_t)0xFC
-
 enum {
 	PRIMARY_PART = 1,
 	SECONDARY_PART,
include/fwu_mdata.h +4 -0
index d2521f39b42e..43b3487c4a23 100644
@@ -9,6 +9,10 @@
 #include <linux/compiler_attributes.h>
 #include <efi.h>
 
+#define FWU_BANK_INVALID	(uint8_t)0xFF
+#define FWU_BANK_VALID		(uint8_t)0xFE
+#define FWU_BANK_ACCEPTED	(uint8_t)0xFC
+
 /**
  * struct fwu_image_bank_info - firmware image information
  * @image_guid: Guid value of the image in this bank
tools/mkfwumdata.c +1 -4
index fbc2067bc12d..0d1697622e6a 100644
@@ -33,9 +33,6 @@ typedef uint64_t u64;
 /* version 2 supports maximum of 4 banks */
 #define MAX_BANKS_V2			4
 
-#define BANK_INVALID			(u8)0xFF
-#define BANK_ACCEPTED			(u8)0xFC
-
 #include <fwu_mdata.h>
 
 static const char *opts_short = "b:i:a:p:v:V:gh";
@@ -297,7 +294,7 @@ static void fwu_fill_version_specific_mdata(struct fwu_mdata_object *mobj)
 
 	for (i = 0; i < MAX_BANKS_V2; i++)
 		mdata->bank_state[i] = i < mobj->banks ?
-			BANK_ACCEPTED : BANK_INVALID;
+			FWU_BANK_ACCEPTED : FWU_BANK_INVALID;
 
 	fw_desc = (struct fwu_fw_store_desc *)((u8 *)mdata + sizeof(*mdata));
 	fw_desc->num_banks = mobj->banks;
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/5 fwu: use FWU_MAX_STATE_BANKS for bank_state array

In reply to Dario Binacchi

Replace the hardcoded size of the bank_state array with FWU_MAX_STATE_BANKS to improve readability and ensure consistency between the structure definition and code that relies on it, including the mkfwumdata tool.

---

 include/fwu_mdata.h | 5 ++++-
 tools/mkfwumdata.c  | 5 +----
 2 files changed, 5 insertions(+), 5 deletions(-)
include/fwu_mdata.h +4 -1
index 43b3487c4a23..b84a9987f769 100644
@@ -94,6 +94,9 @@ struct fwu_mdata {
 } __packed;
 
 #else /* CONFIG_FWU_MDATA_V1 */
+
+#define FWU_MAX_STATE_BANKS			4
+
 /**
  * struct fwu_mdata - FWU metadata structure for multi-bank updates
  * @crc32: crc32 value for the FWU metadata
@@ -120,7 +123,7 @@ struct fwu_mdata {
 	uint32_t metadata_size;
 	uint16_t desc_offset;
 	uint16_t reserved1;
-	uint8_t  bank_state[4];
+	uint8_t  bank_state[FWU_MAX_STATE_BANKS];
 	uint32_t reserved2;
 
 	// struct fwu_fw_store_desc fw_desc;
tools/mkfwumdata.c +1 -4
index 0d1697622e6a..c2fd3d4232f5 100644
@@ -30,9 +30,6 @@ typedef uint64_t u64;
 #define CONFIG_FWU_NUM_BANKS		0
 #define CONFIG_FWU_NUM_IMAGES_PER_BANK	0
 
-/* version 2 supports maximum of 4 banks */
-#define MAX_BANKS_V2			4
-
 #include <fwu_mdata.h>
 
 static const char *opts_short = "b:i:a:p:v:V:gh";
@@ -292,7 +289,7 @@ static void fwu_fill_version_specific_mdata(struct fwu_mdata_object *mobj)
 	mdata->metadata_size = mobj->size;
 	mdata->desc_offset = sizeof(struct fwu_mdata);
 
-	for (i = 0; i < MAX_BANKS_V2; i++)
+	for (i = 0; i < FWU_MAX_STATE_BANKS; i++)
 		mdata->bank_state[i] = i < mobj->banks ?
 			FWU_BANK_ACCEPTED : FWU_BANK_INVALID;
 
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/5 tools: Add dumpfwumdata tool for FWU metadata image

In reply to Dario Binacchi

Allow reading FWU metadata from userspace.

According to [1], after updating the software on bank B, setting active_index to point to it (i. e. 1) and marking it as a Valid bank, it must be possible to read this information from userspace on the next boot to verify whether the boot chain of bank B succeeded.

The metadata must then be updated again, marking the bank as INVALID if the active_index points to bank A (i. e. 0) or as VALID if the boot was successful.

To allow reading the active_index and bank state, this new tool has been added.

---

 tools/Kconfig        |   7 +++
 tools/Makefile       |   4 ++
 tools/dumpfwumdata.c | 128 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)
 create mode 100644 tools/dumpfwumdata.c
tools/Kconfig +7 -0
index 652b0f225579..9de7eed1bbbb 100644
@@ -194,6 +194,13 @@ config LUT_SEQUENCE
 	help
 	  Look Up Table Sequence
 
+config TOOLS_DUMPFWUMDATA
+	bool "Build dumpfwumdata command"
+	default y if FWU_MULTI_BANK_UPDATE
+	help
+	  This command allows users to read and display the raw FWU
+	  metadata. The exact access method depends on the platform.
+
 config TOOLS_MKFWUMDATA
 	bool "Build mkfwumdata command"
 	default y if FWU_MULTI_BANK_UPDATE
tools/Makefile +4 -0
index ae6a30526466..bc105a086927 100644
@@ -271,6 +271,10 @@ mkeficapsule-objs := generated/lib/uuid.o \
 	mkeficapsule.o
 hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule
 
+dumpfwumdata-objs := dumpfwumdata.o generated/lib/crc32.o
+HOSTLDLIBS_dumpfwumdata += -luuid
+hostprogs-$(CONFIG_TOOLS_DUMPFWUMDATA) += dumpfwumdata
+
 mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o
 HOSTLDLIBS_mkfwumdata += -luuid
 hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata
tools/dumpfwumdata.c new file +128 -0

128 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH 4/5] tools: Add dumpfwumdata tool for FWU metadata image

ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi
<[email protected]> napsal:

Quoted 47 lines

Allow reading FWU metadata from userspace.

According to [1], after updating the software on bank B, setting active_index to point to it (i. e. 1) and marking it as a Valid bank, it must be possible to read this information from userspace on the next boot to verify whether the boot chain of bank B succeeded.

The metadata must then be updated again, marking the bank as INVALID if the active_index points to bank A (i. e. 0) or as VALID if the boot was successful.

To allow reading the active_index and bank state, this new tool has been added.

---

 tools/Kconfig        |   7 +++
 tools/Makefile       |   4 ++
 tools/dumpfwumdata.c | 128 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)
 create mode 100644 tools/dumpfwumdata.c
tools/Kconfig +7 -0
index 652b0f225579..9de7eed1bbbb 100644
@@ -194,6 +194,13 @@ config LUT_SEQUENCE
        help
          Look Up Table Sequence
 
+config TOOLS_DUMPFWUMDATA
+       bool "Build dumpfwumdata command"
+       default y if FWU_MULTI_BANK_UPDATE
+       help
+         This command allows users to read and display the raw FWU
+         metadata. The exact access method depends on the platform.
+
 config TOOLS_MKFWUMDATA
        bool "Build mkfwumdata command"
        default y if FWU_MULTI_BANK_UPDATE
tools/Makefile +0 -0
index ae6a30526466..bc105a086927 100644

tools/Makefile mkeficapsule-objs := generated/lib/uuid.o \ · line 276

Quoted 6 lines
tools/Makefile +3 -0
@@ -271,6 +271,10 @@ mkeficapsule-objs := generated/lib/uuid.o \
        mkeficapsule.o
 hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule
 
+dumpfwumdata-objs := dumpfwumdata.o generated/lib/crc32.o
+HOSTLDLIBS_dumpfwumdata += -luuid
+hostprogs-$(CONFIG_TOOLS_DUMPFWUMDATA) += dumpfwumdata

you need to update this based on changes

commit bd3f9ee679b4d1456d0d3c261ab76788950e6096

Author:     Sughosh Ganu <[email protected]>
AuthorDate: Tue Dec 16 11:16:24 2025 +0200
Commit:     Tom Rini <[email protected]>
CommitDate: Fri Jan 2 10:28:14 2026 -0600

kbuild: Bump the build system to 6.1

add missing always.

Quoted 73 lines
tools/Makefile +1 -0
+
 mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o
 HOSTLDLIBS_mkfwumdata += -luuid
 hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata
tools/dumpfwumdata.c new file +63 -0
new file mode 100644
index 000000000000..4965484df1be
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2025, Amarula Solutions
+ */
+
+#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <generated/autoconf.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <u-boot/crc.h>
+#include <uuid/uuid.h>
+
+typedef uint8_t u8;
+typedef int16_t s16;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+
+#undef CONFIG_FWU_NUM_BANKS
+#undef CONFIG_FWU_NUM_IMAGES_PER_BANK
+
+/* This will dynamically allocate the fwu_mdata */
+#define CONFIG_FWU_NUM_BANKS           0
+#define CONFIG_FWU_NUM_IMAGES_PER_BANK 0
+
+#include <fwu_mdata.h>
+
+static const char *opts_short = "h";
+
+static struct option options[] = {
+       {"help", no_argument, NULL, 'h'},
+       {NULL, 0, NULL, 0},
+};
+
+static void print_usage(void)
+{
+       fprintf(stderr, "Usage: dumpfwumdata [options] <fwumdata file>\n");
+       fprintf(stderr, "Options:\n"
+               "\t-h, --help                  print a help message\n"
+               );
+}
+
+static void print_mdata(struct fwu_mdata *data)
+{
+       int i;
+
+       fprintf(stdout, "FWU Metadata\n");
+       fprintf(stdout, "crc32: %#x\n", data->crc32);
+       fprintf(stdout, "version: %#x\n", data->version);
+       fprintf(stdout, "active_index: %#x\n", data->active_index);
+       fprintf(stdout, "previous_active_index: %#x\n",
+               data->previous_active_index);
+
+       if (data->version == 2) {
+               uint8_t state;
+               char cstate;

tools/dumpfwumdata.c line 73

Quoted 10 lines
tools/dumpfwumdata.c new file +10 -0
+               for (i = 0; i < 4; i++) {
+                       state = data->bank_state[i];
+                       if (state == FWU_BANK_ACCEPTED)
+                               cstate = 'A';
+                       else if (state == FWU_BANK_VALID)
+                               cstate = 'V';
+                       else if (state == FWU_BANK_INVALID)
+                               cstate = 'I';
+                       else
+                               cstate = '?';

Isn't it better to print accepted, valid, invalid instead?

I had to look at code to understand what that print value means.

tools/dumpfwumdata.c line 77

Quoted 4 lines
tools/dumpfwumdata.c new file +4 -0
+
+                       printf("bank_state[%d]: %c\n", i, cstate);
+               }
+       }

It is a good start but I think more information should be printed. Number images, custom fields, etc.

Quoted 24 lines
tools/dumpfwumdata.c new file +24 -0
+}
+
+static int fwu_read_mdata(struct fwu_mdata *mdata, const char *mdata_file)
+{
+       FILE *mfile = NULL;
+       size_t ret, size = sizeof(struct fwu_mdata);
+
+       mfile = fopen(mdata_file, "r");
+       if (!mfile) {
+               fprintf(stderr, "Error: Failed to open %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       ret = fread(mdata, 1, size, mfile);
+       fclose(mfile);
+       if (ret != size) {
+               fprintf(stderr, "Error: Failed to read from %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       return 0;
+}

tools/dumpfwumdata.c line 111

Quoted 10 lines
tools/dumpfwumdata.c new file +10 -0
+
+int main(int argc, char *argv[])
+{
+       int c, ret;
+       struct fwu_mdata mdata;
+
+       if (argc < 3) {
+               print_usage();
+               return -EINVAL;
+       }

above you have only help and here you are asking for 3 args which seems to me wrong.

Quoted 18 lines
tools/dumpfwumdata.c new file +17 -1
+
+       do {
+               c = getopt_long(argc, argv, opts_short, options, NULL);
+               switch (c) {
+               case 'h':
+                       print_usage();
+                       return 0;
+               }
+       } while (c != -1);
+
+       ret = fwu_read_mdata(&mdata, argv[argc - 1]);
+       if (ret)
+               return ret;
+
+       print_mdata(&mdata);
+       return 0;
+}
--
Quoted 2 lines

2.43.0

M

Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs
#6 lore raw

Re: [PATCH 4/5] tools: Add dumpfwumdata tool for FWU metadata image

Hello Michal,

Quoted 195 lines · Michal Simek

ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi
<[email protected]> napsal:

Quoted 47 lines

Allow reading FWU metadata from userspace.

According to [1], after updating the software on bank B, setting active_index to point to it (i. e. 1) and marking it as a Valid bank, it must be possible to read this information from userspace on the next boot to verify whether the boot chain of bank B succeeded.

The metadata must then be updated again, marking the bank as INVALID if the active_index points to bank A (i. e. 0) or as VALID if the boot was successful.

To allow reading the active_index and bank state, this new tool has been added.

---

 tools/Kconfig        |   7 +++
 tools/Makefile       |   4 ++
 tools/dumpfwumdata.c | 128 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)
 create mode 100644 tools/dumpfwumdata.c
tools/Kconfig +7 -0
index 652b0f225579..9de7eed1bbbb 100644
@@ -194,6 +194,13 @@ config LUT_SEQUENCE
        help
          Look Up Table Sequence
 
+config TOOLS_DUMPFWUMDATA
+       bool "Build dumpfwumdata command"
+       default y if FWU_MULTI_BANK_UPDATE
+       help
+         This command allows users to read and display the raw FWU
+         metadata. The exact access method depends on the platform.
+
 config TOOLS_MKFWUMDATA
        bool "Build mkfwumdata command"
        default y if FWU_MULTI_BANK_UPDATE
tools/Makefile +0 -0
index ae6a30526466..bc105a086927 100644

tools/Makefile mkeficapsule-objs := generated/lib/uuid.o \ · line 276

Quoted 6 lines
tools/Makefile +3 -0
@@ -271,6 +271,10 @@ mkeficapsule-objs := generated/lib/uuid.o \
        mkeficapsule.o
 hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule
 
+dumpfwumdata-objs := dumpfwumdata.o generated/lib/crc32.o
+HOSTLDLIBS_dumpfwumdata += -luuid
+hostprogs-$(CONFIG_TOOLS_DUMPFWUMDATA) += dumpfwumdata

you need to update this based on changes

commit bd3f9ee679b4d1456d0d3c261ab76788950e6096

Author:     Sughosh Ganu <[email protected]>
AuthorDate: Tue Dec 16 11:16:24 2025 +0200
Commit:     Tom Rini <[email protected]>
CommitDate: Fri Jan 2 10:28:14 2026 -0600

kbuild: Bump the build system to 6.1

add missing always.

Quoted 73 lines
tools/Makefile +1 -0
+
 mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o
 HOSTLDLIBS_mkfwumdata += -luuid
 hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata
tools/dumpfwumdata.c new file +63 -0
new file mode 100644
index 000000000000..4965484df1be
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2025, Amarula Solutions
+ */
+
+#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <generated/autoconf.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <u-boot/crc.h>
+#include <uuid/uuid.h>
+
+typedef uint8_t u8;
+typedef int16_t s16;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+
+#undef CONFIG_FWU_NUM_BANKS
+#undef CONFIG_FWU_NUM_IMAGES_PER_BANK
+
+/* This will dynamically allocate the fwu_mdata */
+#define CONFIG_FWU_NUM_BANKS           0
+#define CONFIG_FWU_NUM_IMAGES_PER_BANK 0
+
+#include <fwu_mdata.h>
+
+static const char *opts_short = "h";
+
+static struct option options[] = {
+       {"help", no_argument, NULL, 'h'},
+       {NULL, 0, NULL, 0},
+};
+
+static void print_usage(void)
+{
+       fprintf(stderr, "Usage: dumpfwumdata [options] <fwumdata file>\n");
+       fprintf(stderr, "Options:\n"
+               "\t-h, --help                  print a help message\n"
+               );
+}
+
+static void print_mdata(struct fwu_mdata *data)
+{
+       int i;
+
+       fprintf(stdout, "FWU Metadata\n");
+       fprintf(stdout, "crc32: %#x\n", data->crc32);
+       fprintf(stdout, "version: %#x\n", data->version);
+       fprintf(stdout, "active_index: %#x\n", data->active_index);
+       fprintf(stdout, "previous_active_index: %#x\n",
+               data->previous_active_index);
+
+       if (data->version == 2) {
+               uint8_t state;
+               char cstate;

tools/dumpfwumdata.c line 73

Quoted 10 lines
tools/dumpfwumdata.c new file +10 -0
+               for (i = 0; i < 4; i++) {
+                       state = data->bank_state[i];
+                       if (state == FWU_BANK_ACCEPTED)
+                               cstate = 'A';
+                       else if (state == FWU_BANK_VALID)
+                               cstate = 'V';
+                       else if (state == FWU_BANK_INVALID)
+                               cstate = 'I';
+                       else
+                               cstate = '?';

Isn't it better to print accepted, valid, invalid instead?

I had to look at code to understand what that print value means.

tools/dumpfwumdata.c line 77

Quoted 4 lines
tools/dumpfwumdata.c new file +4 -0
+
+                       printf("bank_state[%d]: %c\n", i, cstate);
+               }
+       }

It is a good start but I think more information should be printed. Number images, custom fields, etc.

Quoted 29 lines
tools/dumpfwumdata.c new file +29 -0
+}
+
+static int fwu_read_mdata(struct fwu_mdata *mdata, const char *mdata_file)
+{
+       FILE *mfile = NULL;
+       size_t ret, size = sizeof(struct fwu_mdata);
+
+       mfile = fopen(mdata_file, "r");
+       if (!mfile) {
+               fprintf(stderr, "Error: Failed to open %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       ret = fread(mdata, 1, size, mfile);
+       fclose(mfile);
+       if (ret != size) {
+               fprintf(stderr, "Error: Failed to read from %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       int c, ret;
+       struct fwu_mdata mdata;
Quoted 8 lines

tools/dumpfwumdata.c line 111

Quoted 5 lines
tools/dumpfwumdata.c new file +5 -0
+
+       if (argc < 3) {
+               print_usage();
+               return -EINVAL;
+       }

above you have only help and here you are asking for 3 args which seems to me wrong.

Thank you for your review and the feedback on my patch series. After I sent the series, I realized that this series had previously been posted:
https://lore.kernel.org/all/[email protected]/.
From what I understand, it starts from the same need as mine, namely the implementation of a tool that
allows reading FWU metadata from Linux. My version is definitely more minimal compared to what Kory
has done.
Therefore, before sending a v2, I think it would be useful to understand which of the two makes more sense
to move forward with. Could you help me with that? I have also CCed Kory to keep the discussion shared.

Thanks and regards,
Dario

Quoted 31 lines
Quoted 19 lines
tools/dumpfwumdata.c new file +17 -1
+
+       do {
+               c = getopt_long(argc, argv, opts_short, options, NULL);
+               switch (c) {
+               case 'h':
+                       print_usage();
+                       return 0;
+               }
+       } while (c != -1);
+
+       ret = fwu_read_mdata(&mdata, argv[argc - 1]);
+       if (ret)
+               return ret;
+
+       print_mdata(&mdata);
+       return 0;
+}
--
Quoted 2 lines

2.43.0

M

--
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs

Signature · 17 lines
Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com
#7 lore raw

Re: [PATCH 4/5] tools: Add dumpfwumdata tool for FWU metadata image

Quoted 207 lines · Dario Binacchi

Hello Michal,

Quoted 195 lines · Michal Simek

ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi
<[email protected]> napsal:

Quoted 47 lines

Allow reading FWU metadata from userspace.

According to [1], after updating the software on bank B, setting active_index to point to it (i. e. 1) and marking it as a Valid bank, it must be possible to read this information from userspace on the next boot to verify whether the boot chain of bank B succeeded.

The metadata must then be updated again, marking the bank as INVALID if the active_index points to bank A (i. e. 0) or as VALID if the boot was successful.

To allow reading the active_index and bank state, this new tool has been added.

---

  tools/Kconfig        |   7 +++
  tools/Makefile       |   4 ++
  tools/dumpfwumdata.c | 128 +++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 139 insertions(+)

create mode 100644 tools/dumpfwumdata.c

tools/Kconfig +7 -0
index 652b0f225579..9de7eed1bbbb 100644
@@ -194,6 +194,13 @@ config LUT_SEQUENCE
         help
           Look Up Table Sequence
 
+config TOOLS_DUMPFWUMDATA
+       bool "Build dumpfwumdata command"
+       default y if FWU_MULTI_BANK_UPDATE
+       help
+         This command allows users to read and display the raw FWU
+         metadata. The exact access method depends on the platform.
+
  config TOOLS_MKFWUMDATA
         bool "Build mkfwumdata command"
         default y if FWU_MULTI_BANK_UPDATE
tools/Makefile +0 -0
index ae6a30526466..bc105a086927 100644

tools/Makefile mkeficapsule-objs := generated/lib/uuid.o \ · line 276

Quoted 6 lines
tools/Makefile +3 -0
@@ -271,6 +271,10 @@ mkeficapsule-objs := generated/lib/uuid.o \
         mkeficapsule.o
  hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule
 
+dumpfwumdata-objs := dumpfwumdata.o generated/lib/crc32.o
+HOSTLDLIBS_dumpfwumdata += -luuid
+hostprogs-$(CONFIG_TOOLS_DUMPFWUMDATA) += dumpfwumdata

you need to update this based on changes

commit bd3f9ee679b4d1456d0d3c261ab76788950e6096

Author:     Sughosh Ganu <[email protected]>
AuthorDate: Tue Dec 16 11:16:24 2025 +0200
Commit:     Tom Rini <[email protected]>
CommitDate: Fri Jan 2 10:28:14 2026 -0600

kbuild: Bump the build system to 6.1

add missing always.

Quoted 73 lines
tools/Makefile +1 -0
+
  mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o
  HOSTLDLIBS_mkfwumdata += -luuid
  hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata
tools/dumpfwumdata.c new file +63 -0
new file mode 100644
index 000000000000..4965484df1be
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2025, Amarula Solutions
+ */
+
+#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <generated/autoconf.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <u-boot/crc.h>
+#include <uuid/uuid.h>
+
+typedef uint8_t u8;
+typedef int16_t s16;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+
+#undef CONFIG_FWU_NUM_BANKS
+#undef CONFIG_FWU_NUM_IMAGES_PER_BANK
+
+/* This will dynamically allocate the fwu_mdata */
+#define CONFIG_FWU_NUM_BANKS           0
+#define CONFIG_FWU_NUM_IMAGES_PER_BANK 0
+
+#include <fwu_mdata.h>
+
+static const char *opts_short = "h";
+
+static struct option options[] = {
+       {"help", no_argument, NULL, 'h'},
+       {NULL, 0, NULL, 0},
+};
+
+static void print_usage(void)
+{
+       fprintf(stderr, "Usage: dumpfwumdata [options] <fwumdata file>\n");
+       fprintf(stderr, "Options:\n"
+               "\t-h, --help                  print a help message\n"
+               );
+}
+
+static void print_mdata(struct fwu_mdata *data)
+{
+       int i;
+
+       fprintf(stdout, "FWU Metadata\n");
+       fprintf(stdout, "crc32: %#x\n", data->crc32);
+       fprintf(stdout, "version: %#x\n", data->version);
+       fprintf(stdout, "active_index: %#x\n", data->active_index);
+       fprintf(stdout, "previous_active_index: %#x\n",
+               data->previous_active_index);
+
+       if (data->version == 2) {
+               uint8_t state;
+               char cstate;

tools/dumpfwumdata.c line 73

Quoted 10 lines
tools/dumpfwumdata.c new file +10 -0
+               for (i = 0; i < 4; i++) {
+                       state = data->bank_state[i];
+                       if (state == FWU_BANK_ACCEPTED)
+                               cstate = 'A';
+                       else if (state == FWU_BANK_VALID)
+                               cstate = 'V';
+                       else if (state == FWU_BANK_INVALID)
+                               cstate = 'I';
+                       else
+                               cstate = '?';

Isn't it better to print accepted, valid, invalid instead?

I had to look at code to understand what that print value means.

tools/dumpfwumdata.c line 77

Quoted 4 lines
tools/dumpfwumdata.c new file +4 -0
+
+                       printf("bank_state[%d]: %c\n", i, cstate);
+               }
+       }

It is a good start but I think more information should be printed. Number images, custom fields, etc.

Quoted 29 lines
tools/dumpfwumdata.c new file +29 -0
+}
+
+static int fwu_read_mdata(struct fwu_mdata *mdata, const char *mdata_file)
+{
+       FILE *mfile = NULL;
+       size_t ret, size = sizeof(struct fwu_mdata);
+
+       mfile = fopen(mdata_file, "r");
+       if (!mfile) {
+               fprintf(stderr, "Error: Failed to open %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       ret = fread(mdata, 1, size, mfile);
+       fclose(mfile);
+       if (ret != size) {
+               fprintf(stderr, "Error: Failed to read from %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       int c, ret;
+       struct fwu_mdata mdata;
Quoted 8 lines

tools/dumpfwumdata.c line 111

Quoted 5 lines
tools/dumpfwumdata.c new file +5 -0
+
+       if (argc < 3) {
+               print_usage();
+               return -EINVAL;
+       }

above you have only help and here you are asking for 3 args which seems to me wrong.

Quoted 13 lines

Thank you for your review and the feedback on my patch series. After I sent the series, I realized that this series had previously been posted:
https://lore.kernel.org/all/[email protected]/.
From what I understand, it starts from the same need as mine, namely
the implementation of a tool that
allows reading FWU metadata from Linux. My version is definitely more minimal compared to what Kory
has done.
Therefore, before sending a v2, I think it would be useful to understand which of the two makes more sense
to move forward with. Could you help me with that? I have also CCed Kory to keep the discussion shared.

Kory's version looks more complete. If Kory is happy to send another version I think you should test it, review it. If he is not going to send v3 I think you should merge your series with his and send another version.

Thanks,
Michal

#8 lore raw

Re: [PATCH 4/5] tools: Add dumpfwumdata tool for FWU metadata image

Quoted 23 lines · On Mon, 12 Jan 2026 10:05:50 +0100 Michal Simek <[email protected]> wrote:
Quoted 22 lines · Dario Binacchi

Hello Michal,

Quoted 19 lines · Michal Simek

ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi
<[email protected]> napsal:

Quoted 16 lines

Allow reading FWU metadata from userspace.

According to [1], after updating the software on bank B, setting active_index to point to it (i. e. 1) and marking it as a Valid bank, it must be possible to read this information from userspace on the next boot to verify whether the boot chain of bank B succeeded.

The metadata must then be updated again, marking the bank as INVALID if the active_index points to bank A (i. e. 0) or as VALID if the boot was successful.

To allow reading the active_index and bank state, this new tool has been added.

...

Quoted 52 lines
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
tools/dumpfwumdata.c new file +3 -0
+}
+
+static int fwu_read_mdata(struct fwu_mdata *mdata, const char

*mdata_file) +{

tools/dumpfwumdata.c new file +25 -0
+       FILE *mfile = NULL;
+       size_t ret, size = sizeof(struct fwu_mdata);
+
+       mfile = fopen(mdata_file, "r");
+       if (!mfile) {
+               fprintf(stderr, "Error: Failed to open %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       ret = fread(mdata, 1, size, mfile);
+       fclose(mfile);
+       if (ret != size) {
+               fprintf(stderr, "Error: Failed to read from %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       int c, ret;
+       struct fwu_mdata mdata;
Quoted 8 lines

tools/dumpfwumdata.c line 111

Quoted 5 lines
tools/dumpfwumdata.c new file +5 -0
+
+       if (argc < 3) {
+               print_usage();
+               return -EINVAL;
+       }  

above you have only help and here you are asking for 3 args which seems to me wrong.

Quoted 13 lines

Thank you for your review and the feedback on my patch series. After I sent the series, I realized that this series had previously been posted:
https://lore.kernel.org/all/[email protected]/.
From what I understand, it starts from the same need as mine, namely
the implementation of a tool that
allows reading FWU metadata from Linux. My version is definitely more minimal compared to what Kory
has done.
Therefore, before sending a v2, I think it would be useful to understand which of the two makes more sense
to move forward with. Could you help me with that? I have also CCed Kory to keep the discussion shared.

Quoted 3 lines

Kory's version looks more complete. If Kory is happy to send another version I think you should test it, review it. If he is not going to send v3 I think you should merge your series with his and send another version.

Hello,

I was going to ping reviews on my series.
I will be glad to send a 3rd version but there will be no change from v2 as nobody reviewed it for now, but if needed I can resend it.
It would be nice if you review and test it on you side to know if it match your requirements.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#9 lore raw

Re: [PATCH 4/5] tools: Add dumpfwumdata tool for FWU metadata image

Hello Kory,

Quoted 86 lines · Kory Maincent
Quoted 23 lines · On Mon, 12 Jan 2026 10:05:50 +0100 Michal Simek <[email protected]> wrote:
Quoted 22 lines · Dario Binacchi

Hello Michal,

Quoted 19 lines · Michal Simek

ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi
<[email protected]> napsal:

Quoted 16 lines

Allow reading FWU metadata from userspace.

According to [1], after updating the software on bank B, setting active_index to point to it (i. e. 1) and marking it as a Valid bank, it must be possible to read this information from userspace on the next boot to verify whether the boot chain of bank B succeeded.

The metadata must then be updated again, marking the bank as INVALID if the active_index points to bank A (i. e. 0) or as VALID if the boot was successful.

To allow reading the active_index and bank state, this new tool has been added.

...

Quoted 52 lines
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
tools/dumpfwumdata.c new file +3 -0
+}
+
+static int fwu_read_mdata(struct fwu_mdata *mdata, const char

*mdata_file) +{

tools/dumpfwumdata.c new file +25 -0
+       FILE *mfile = NULL;
+       size_t ret, size = sizeof(struct fwu_mdata);
+
+       mfile = fopen(mdata_file, "r");
+       if (!mfile) {
+               fprintf(stderr, "Error: Failed to open %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       ret = fread(mdata, 1, size, mfile);
+       fclose(mfile);
+       if (ret != size) {
+               fprintf(stderr, "Error: Failed to read from %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       int c, ret;
+       struct fwu_mdata mdata;
Quoted 8 lines

tools/dumpfwumdata.c line 111

Quoted 5 lines
tools/dumpfwumdata.c new file +5 -0
+
+       if (argc < 3) {
+               print_usage();
+               return -EINVAL;
+       }

above you have only help and here you are asking for 3 args which seems to me wrong.

Quoted 13 lines

Thank you for your review and the feedback on my patch series. After I sent the series, I realized that this series had previously been posted:
https://lore.kernel.org/all/[email protected]/.
From what I understand, it starts from the same need as mine, namely
the implementation of a tool that
allows reading FWU metadata from Linux. My version is definitely more minimal compared to what Kory
has done.
Therefore, before sending a v2, I think it would be useful to understand which of the two makes more sense
to move forward with. Could you help me with that? I have also CCed Kory to keep the discussion shared.

Quoted 3 lines

Kory's version looks more complete. If Kory is happy to send another version I think you should test it, review it. If he is not going to send v3 I think you should merge your series with his and send another version.

Quoted 7 lines

Hello,

I was going to ping reviews on my series.
I will be glad to send a 3rd version but there will be no change from v2 as nobody reviewed it for now, but if needed I can resend it.
It would be nice if you review and test it on you side to know if it match your requirements.

I'll be resuming work on swupdate for our STM32MP-based custom board shortly and will test your series as soon as possible.

Just one question: I was expecting the introduction of a tool to read the data contained in fwu-metadata. Why does your new tool also add write functionality, considering that mkfwumdata already exists?

Thanks and regards,

Dario

Quoted 6 lines

Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

Signature · 17 lines
Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com
#10 lore raw

Re: [PATCH 4/5] tools: Add dumpfwumdata tool for FWU metadata image

Quoted 99 lines · On Sat, 17 Jan 2026 12:11:18 +0100 Dario Binacchi…

Hello Kory,

Quoted 87 lines · Kory Maincent
Quoted 23 lines · On Mon, 12 Jan 2026 10:05:50 +0100 Michal Simek <[email protected]> wrote:
Quoted 22 lines · Dario Binacchi

Hello Michal,

Quoted 19 lines · Michal Simek

ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi
<[email protected]> napsal:

Quoted 16 lines

Allow reading FWU metadata from userspace.

According to [1], after updating the software on bank B, setting active_index to point to it (i. e. 1) and marking it as a Valid bank, it must be possible to read this information from userspace on the next boot to verify whether the boot chain of bank B succeeded.

The metadata must then be updated again, marking the bank as INVALID if the active_index points to bank A (i. e. 0) or as VALID if the boot was successful.

To allow reading the active_index and bank state, this new tool has been added.

...

Quoted 52 lines
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
tools/dumpfwumdata.c new file +3 -0
+}
+
+static int fwu_read_mdata(struct fwu_mdata *mdata, const char

*mdata_file) +{

tools/dumpfwumdata.c new file +25 -0
+       FILE *mfile = NULL;
+       size_t ret, size = sizeof(struct fwu_mdata);
+
+       mfile = fopen(mdata_file, "r");
+       if (!mfile) {
+               fprintf(stderr, "Error: Failed to open %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       ret = fread(mdata, 1, size, mfile);
+       fclose(mfile);
+       if (ret != size) {
+               fprintf(stderr, "Error: Failed to read from %s\n",
+                       mdata_file);
+               return -1;
+       }
+
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       int c, ret;
+       struct fwu_mdata mdata;
Quoted 8 lines

tools/dumpfwumdata.c line 111

Quoted 5 lines
tools/dumpfwumdata.c new file +5 -0
+
+       if (argc < 3) {
+               print_usage();
+               return -EINVAL;
+       }  

above you have only help and here you are asking for 3 args which seems to me wrong.

Quoted 13 lines

Thank you for your review and the feedback on my patch series. After I sent the series, I realized that this series had previously been posted:
https://lore.kernel.org/all/[email protected]/.
From what I understand, it starts from the same need as mine, namely
the implementation of a tool that
allows reading FWU metadata from Linux. My version is definitely more minimal compared to what Kory
has done.
Therefore, before sending a v2, I think it would be useful to understand which of the two makes more sense
to move forward with. Could you help me with that? I have also CCed Kory to keep the discussion shared.

Quoted 4 lines

Kory's version looks more complete. If Kory is happy to send another version I think you should test it, review it. If he is not going to send v3 I think you should merge your series with his and send another version.

Quoted 7 lines

Hello,

I was going to ping reviews on my series.
I will be glad to send a 3rd version but there will be no change from v2 as nobody reviewed it for now, but if needed I can resend it.
It would be nice if you review and test it on you side to know if it match your requirements.

Quoted 6 lines

I'll be resuming work on swupdate for our STM32MP-based custom board shortly and will test your series as soon as possible.

Just one question: I was expecting the introduction of a tool to read the data contained in fwu-metadata. Why does your new tool also add write functionality, considering that mkfwumdata already exists?

Hello,

Because we don't want to generate a new FWU metadata every time and then write it on the FWU metadata partition. It is better to read and edit part of it directly with the same tool.
The way I saw it was that mkfwumdata should only to be used on the host side to generate the first FWU metadata.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#11 lore raw

PATCH 5/5 tools: build dumpfwumdata with tools-only_defconfig

In reply to Dario Binacchi

Always build dumpfwumdata when using tools-only_defconfig.

---

 configs/tools-only_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/tools-only_defconfig +1 -0
index bdc646e29b32..bbcb64879fac 100644
@@ -41,3 +41,4 @@ CONFIG_VIRTIO_SANDBOX=n
 CONFIG_GENERATE_ACPI_TABLE=n
 CONFIG_TOOLS_MKEFICAPSULE=y
 CONFIG_TOOLS_MKFWUMDATA=y
+CONFIG_TOOLS_DUMPFWUMDATA=y
Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH 5/5] tools: build dumpfwumdata with tools-only_defconfig

ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi
<[email protected]> napsal:

Quoted 15 lines

Always build dumpfwumdata when using tools-only_defconfig.

---

 configs/tools-only_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/tools-only_defconfig +0 -0
index bdc646e29b32..bbcb64879fac 100644

configs/tools-only_defconfig CONFIG_VIRTIO_SANDBOX=n · line 44

Quoted 4 lines
configs/tools-only_defconfig +1 -0
@@ -41,3 +41,4 @@ CONFIG_VIRTIO_SANDBOX=n
 CONFIG_GENERATE_ACPI_TABLE=n
 CONFIG_TOOLS_MKEFICAPSULE=y
 CONFIG_TOOLS_MKFWUMDATA=y
+CONFIG_TOOLS_DUMPFWUMDATA=y

Order is different. This should be above CONFIG_TOOLS_MKFWUMDATA.

M