Add support for fwumdata
v4 cover Add support for fwumdata
Add a new fwumdata tool to allows users to read, display, and modify FWU (Firmware Update) metadata from Linux userspace. It provides functionality similar to fw_printenv/fw_setenv but for FWU metadata. Users can view metadata, change active/previous bank indices, modify bank states, and set image acceptance flags. Configuration is done via fwumdata.config file.
Made a few change to mkfwumdata tool along the way.
Here is an output example
$ ./fwumdata -l FWU Metadata: Version: 2 Active Index: 0 Previous Index: 1 CRC32: 0x1f21ff7b Metadata Size: 120 bytes Descriptor Offset: 32 Bank States: Bank 0: accepted (0xfc) Bank 1: accepted (0xfc)
Firmware Store Descriptor:
Number of Banks: 2
Number of Images: 1
Image Entry Size: 80
Bank Info Entry Size: 24
Images:
Image 0:
Image Type GUID: 65ae85ad-1fb3-0b46-8c5d-285543aa6eab
Location GUID: 51513491-da07-2a4f-9bea-375ea53b1b5c
Banks:
Bank 0:
Image GUID: cb2df442-f929-6a44-a374-672d92eb2aa7
Accepted: yes (1)
Bank 1:
Image GUID: a839a18f-395c-484f-83b8-0354077c8f9f
Accepted: yes (1)
Changes in v4:
- Add missing "always" suffix in Makefile description
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Rebase on master.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Fix a small offset mistake in last patch
---
Kory Maincent (6):
tools: gitignore: Add mkfwumdata to the git ignore file
tools: Reorganize mkfwumdata tool into fwumdata_src directory
tools: mkfwumdata: Improve error message specificity
tools: mkfwumdata: Add bank count validation for FWU metadata v2
tools: Add support for fwumdata tool
tools: mkfwumdata: Remove dependency on fwu_mdata.h header
MAINTAINERS | 7 +-
doc/develop/uefi/fwu_updates.rst | 4 +-
doc/fwumdata.1 | 222 +++++++++
tools/.gitignore | 2 +
tools/Kconfig | 9 +-
tools/Makefile | 4 +-
tools/fwumdata_src/Kconfig | 19 +
tools/fwumdata_src/fwumdata.c | 854 ++++++++++++++++++++++++++++++++++
tools/fwumdata_src/fwumdata.config | 33 ++
tools/fwumdata_src/fwumdata.h | 138 ++++++
tools/fwumdata_src/fwumdata.mk | 10 +
tools/{ => fwumdata_src}/mkfwumdata.c | 106 ++---
12 files changed, 1315 insertions(+), 93 deletions(-)---
base-commit: 30b8c03d8c8f500b3e4cc51f7b7abf573180ea51
change-id: 20251107-feature_fwumdata-58508d61e1d3
Best regards,
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
PATCH v4 1/6 tools: gitignore: Add mkfwumdata to the git ignore file
mkfwumdata is a built image. Add it to .gitignore.
--- tools/.gitignore | 1 + 1 file changed, 1 insertion(+)
tools/.gitignore +1 -0
@@ -24,6 +24,7 @@ /mkeficapsule /mkenvimage /mkexynosspl +/mkfwumdata /mkimage /mksunxiboot /mxsboot
Signature · 1 line
2.43.0
PATCH v4 2/6 tools: Reorganize mkfwumdata tool into fwumdata_src directory
In reply to Kory MaincentUpdate FWU metadata-related tools by moving mkfwumdata.c into a new tools/fwumdata_src/ directory structure. This refactoring prepares for the addition of the fwumdata runtime tool, which will allow editing FWU metadata directly from the target.
The Kconfig and Makefile entries are also moved into separate files within the new directory (Kconfig and fwumdata.mk respectively) to keep all FWU metadata tool configurations together and improve maintainability.
---
MAINTAINERS | 3 ++-
tools/Kconfig | 9 +--------
tools/Makefile | 4 +---
tools/fwumdata_src/Kconfig | 8 ++++++++
tools/fwumdata_src/fwumdata.mk | 7 +++++++
tools/{ => fwumdata_src}/mkfwumdata.c | 0
6 files changed, 19 insertions(+), 12 deletions(-)MAINTAINERS +2 -1
@@ -1242,9 +1242,10 @@ FWU Multi Bank Update M: Sughosh Ganu <[email protected]> S: Maintained T: git https://source.denx.de/u-boot/custodians/u-boot-efi.git +F: doc/mkfwumdata.1 F: lib/fwu_updates/* F: drivers/fwu-mdata/* -F: tools/mkfwumdata.c +F: tools/fwumdata_src/mkfwumdata.c GATEWORKS_SC M: Tim Harvey <[email protected]>
tools/Kconfig +1 -8
@@ -194,13 +194,6 @@ 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. +source tools/fwumdata_src/Kconfig endmenu
tools/Makefile +1 -3
@@ -272,9 +272,7 @@ mkeficapsule-objs := generated/lib/uuid.o \ mkeficapsule.o hostprogs-always-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule -mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o -HOSTLDLIBS_mkfwumdata += -luuid -hostprogs-always-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata +include tools/fwumdata_src/fwumdata.mk # 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
tools/fwumdata_src/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +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.
tools/fwumdata_src/fwumdata.mk new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# (C) Copyright 2025, Kory Maincent <[email protected]> + +mkfwumdata-objs := fwumdata_src/mkfwumdata.o generated/lib/crc32.o +HOSTLDLIBS_mkfwumdata += -luuid +hostprogs-always-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata
tools/fwumdata_src/mkfwumdata.c renamed from tools/mkfwumdata.c +0 -0
Signature · 1 line
2.43.0
PATCH v4 3/6 tools: mkfwumdata: Improve error message specificity
In reply to Kory MaincentReplace the generic error message with a more informative one. This helps users quickly understand the correct command-line argument format when the tool reports an error.
--- tools/fwumdata_src/mkfwumdata.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/fwumdata_src/mkfwumdata.c +3 -1
@@ -473,7 +473,9 @@ int main(int argc, char *argv[])/* This command takes UUIDs * images and output file. */ if (optind + images +1 != argc) { -fprintf (stderr,"Error: UUID list or output file is not specified or too much.\n" ); +fprintf (stderr, +"Error: Expected %ld UUID string(s) and 1 output file, got %d argument(s).\n" , + images, argc - optind);print_usage ();return -ERANGE ; }
Signature · 1 line
2.43.0
PATCH v4 4/6 tools: mkfwumdata: Add bank count validation for FWU metadata v2
In reply to Kory MaincentThe FWU metadata specification version 2 supports a maximum of 4 banks. Add validation to enforce this limit and prevent creation of non-compliant metadata structures when using version 2.
Without this check, users could inadvertently create invalid metadata by specifying more than 4 banks, leading to potential compatibility issues with FWU-compliant firmware update implementations.
--- tools/fwumdata_src/mkfwumdata.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/fwumdata_src/mkfwumdata.c +6 -0
@@ -471,6 +471,12 @@ int main(int argc, char *argv[])return -EINVAL ; } +if (version ==2 && banks >MAX_BANKS_V2 ) { +fprintf (stderr,"Error: Version 2 supports maximum %d banks, %ld requested.\n" , +MAX_BANKS_V2 , banks); +return -EINVAL ; + } +/* This command takes UUIDs * images and output file. */ if (optind + images +1 != argc) { fprintf(stderr,
Signature · 1 line
2.43.0
PATCH v4 5/6 tools: Add support for fwumdata tool
In reply to Kory MaincentAdd a new fwumdata tool to allows users to read, display, and modify FWU (Firmware Update) metadata from Linux userspace. It provides functionality similar to fw_printenv/fw_setenv but for FWU metadata. Users can view metadata, change active/previous bank indices, modify bank states, and set image acceptance flags. Configuration is done via fwumdata.config file.
---
Change in v4:
- Add missing "always" suffix in Makefile description
--- MAINTAINERS | 4 + doc/develop/uefi/fwu_updates.rst | 4 +- doc/fwumdata.1 | 222 ++++++++++ tools/.gitignore | 1 + tools/fwumdata_src/Kconfig | 11 + tools/fwumdata_src/fwumdata.c | 854 +++++++++++++++++++++++++++++++++++++ tools/fwumdata_src/fwumdata.config | 33 ++ tools/fwumdata_src/fwumdata.h | 138 ++++++ tools/fwumdata_src/fwumdata.mk | 3 + 9 files changed, 1269 insertions(+), 1 deletion(-)
MAINTAINERS +4 -0
@@ -1240,11 +1240,15 @@ F: drivers/watchdog/sbsa_gwdt.c FWU Multi Bank Update M: Sughosh Ganu <[email protected]> +M: Kory Maincent <[email protected]> S: Maintained T: git https://source.denx.de/u-boot/custodians/u-boot-efi.git +F: doc/fwumdata.1 F: doc/mkfwumdata.1 F: lib/fwu_updates/* F: drivers/fwu-mdata/* +F: tools/fwumdata_src/fwumdata.c +F: tools/fwumdata_src/fwumdata.h F: tools/fwumdata_src/mkfwumdata.c GATEWORKS_SC
doc/develop/uefi/fwu_updates.rst +3 -1
@@ -66,7 +66,9 @@ FWU Metadata U-Boot supports both versions(1 and 2) of the FWU metadata defined in the two revisions of the specification. Support can be enabled for either of the two versions through a config flag. The mkfwumdata tool -can generate metadata for both the supported versions. +can generate metadata for both the supported versions. On the target side, +the fwumdata tool can read and update FWU metadata located in memory, +similarly to how fw_printenv/fw_setenv works. Setting up the device for GPT partitioned storage -------------------------------------------------
doc/fwumdata.1 new file +222 -0
222 lines not on this page · raw message
tools/.gitignore +1 -0
@@ -11,6 +11,7 @@ /file2include /fit_check_sign /fit_info +/fwumdata /gdb/gdbcont /gdb/gdbsend /gen_eth_addr
tools/fwumdata_src/Kconfig +11 -0
@@ -6,3 +6,14 @@ config TOOLS_MKFWUMDATA metadata for initial installation of the FWU multi bank update on the board. The installation method depends on the platform. + +config TOOLS_FWUMDATA + bool "Build fwumdata command" + default y if FWU_MULTI_BANK_UPDATE + help + This command allows users to read, display, and modify FWU + (Firmware Update) metadata from Linux userspace. It provides + functionality similar to fw_printenv/fw_setenv but for FWU + metadata. Users can view metadata, change active/previous + bank indices, modify bank states, and set image acceptance + flags. Configuration is done via fwumdata.config file.
tools/fwumdata_src/fwumdata.c new file +854 -0
854 lines not on this page · raw message
tools/fwumdata_src/fwumdata.config new file +33 -0
@@ -0,0 +1,33 @@ +# FWU Metadata Configuration File +# +# Format: <device> <offset> <metadata_size> <erase_size> +# +# This file describes where the FWU metadata is stored. You can specify +# up to two entries for redundant metadata copies. +# +# Device: MTD device (/dev/mtdX), block device (/dev/mmcblkX), or file path +# Offset: Byte offset from start of device (hex with 0x prefix) +# Metadata Size: Size of metadata structure in bytes (hex with 0x prefix) +# Erase Size: Sector/erase block size (hex with 0x prefix, defaults to +# metadata_size, required only for MTD device) +# +# Examples: +# +# MTD devices (NOR/NAND flash): +# /dev/mtd0 0x0 0x1000 0x1000 +# /dev/mtd1 0x0 0x1000 0x1000 +# +# Block device (eMMC/SD): +# /dev/mmcblk0 0x100000 0x78 +# /dev/mmcblk0 0x101000 0x78 +# +# or: +# /dev/disk/by-partlabel/metadata1 0 0x78 +# /dev/disk/by-partlabel/metadata2 0 0x78 +# +# Regular file: +# /boot/fwu-mdata.bin 0x0 0x78 +# +# Default configuration (update for your platform): +/dev/mtd0 0x0 0x78 0x1000 +/dev/mtd1 0x0 0x78 0x1000
tools/fwumdata_src/fwumdata.h new file +138 -0
138 lines not on this page · raw message
tools/fwumdata_src/fwumdata.mk +3 -0
@@ -5,3 +5,6 @@ mkfwumdata-objs := fwumdata_src/mkfwumdata.o generated/lib/crc32.o HOSTLDLIBS_mkfwumdata += -luuid hostprogs-always-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata + +fwumdata-objs := fwumdata_src/fwumdata.o generated/lib/crc32.o +hostprogs-always-$(CONFIG_TOOLS_FWUMDATA) += fwumdata
Signature · 1 line
2.43.0
PATCH v4 6/6 tools: mkfwumdata: Remove dependency on fwu_mdata.h header
In reply to Kory MaincentThe dependency on fwu_mdata.h creates unnecessary configuration requirements. To generate metadata V1, CONFIG_FWU_MDATA_V1 must be enabled, which in turn requires enabling FWU_MULTI_BANK_UPDATE, EFI_CAPSULE_ON_DISK, PARTITION_TYPE_GUID, and other unrelated configs. This is not suitable for a simple standalone tool.
Additionally, even with the "-v 1" option to generate V1 metadata, the tool will still include the firmware store description if CONFIG_FWU_MDATA_V1 is not enabled. This structure should only be present in metadata V2.
Replace the fwu_mdata.h dependency with the new fwumdata header to make the tool compatible with both V1 and V2 without requiring any defconfig changes. This also uses the access helper functions from the header to eliminate code duplication.
---
Change in v2:
- Fix mdata->desc_offset value.
--- tools/fwumdata_src/mkfwumdata.c | 96 ++++++++--------------------------------- 1 file changed, 17 insertions(+), 79 deletions(-)
tools/fwumdata_src/mkfwumdata.c +17 -79
@@ -17,26 +17,7 @@#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 - -/* 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> +#include "fwumdata.h" static const char *opts_short ="b:i:a:p:v:V:gh" ;
@@ -116,6 +97,7 @@ static struct fwu_mdata_object *fwu_alloc_mdata(size_t images, size_t banks, sizeof(struct fwu_image_bank_info) * banks) * images; }else { mobj->size =sizeof (struct fwu_mdata ) + +sizeof (struct fwu_mdata_ext ) +sizeof (struct fwu_fw_store_desc ) + (sizeof (struct fwu_image_entry ) +sizeof (struct fwu_image_bank_info ) * banks) * images;
@@ -146,50 +128,6 @@ alloc_err:return NULL ; } -static struct fwu_image_entry * -fwu_get_image (struct fwu_mdata_object *mobj,size_t idx) -{ -size_t offset; - -if (mobj->version ==1 ) { - offset =sizeof (struct fwu_mdata ) + - (sizeof (struct fwu_image_entry ) + -sizeof (struct fwu_image_bank_info ) * mobj->banks) * - idx; - }else { - offset =sizeof (struct fwu_mdata ) + -sizeof (struct fwu_fw_store_desc ) + - (sizeof (struct fwu_image_entry ) + -sizeof (struct fwu_image_bank_info ) * mobj->banks) * - idx; - } - -return (struct fwu_image_entry *)((char *)mobj->mdata + offset); -} - -static struct fwu_image_bank_info * -fwu_get_bank (struct fwu_mdata_object *mobj,size_t img_idx,size_t bnk_idx) -{ -size_t offset; - -if (mobj->version ==1 ) { - offset =sizeof (struct fwu_mdata ) + - (sizeof (struct fwu_image_entry ) + -sizeof (struct fwu_image_bank_info ) * mobj->banks) * - img_idx +sizeof (struct fwu_image_entry ) + -sizeof (struct fwu_image_bank_info ) * bnk_idx; - }else { - offset =sizeof (struct fwu_mdata ) + -sizeof (struct fwu_fw_store_desc ) + - (sizeof (struct fwu_image_entry ) + -sizeof (struct fwu_image_bank_info ) * mobj->banks) * - img_idx +sizeof (struct fwu_image_entry ) + -sizeof (struct fwu_image_bank_info ) * bnk_idx; - } - -return (struct fwu_image_bank_info *)((char *)mobj->mdata + offset); -} -/** * convert_uuid_to_guid() - convert UUID to GUID * @buf: UUID binary
@@ -239,11 +177,13 @@ static int fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj, size_t idx, char *uuids) { - struct fwu_image_entry *image = fwu_get_image(mobj, idx); struct fwu_image_bank_info *bank; +struct fwu_image_entry *image;char *p = uuids, *uuid;int i; + image =fwu_get_image_entry (mobj->mdata, mobj->version, + mobj->banks, idx);if (!image)return -ENOENT ;
@@ -266,7 +206,8 @@ fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj,/* Fill bank image-UUID */ for (i =0 ; i < mobj->banks; i++) { - bank =fwu_get_bank (mobj, idx, i); + bank =fwu_get_bank_info (mobj->mdata, mobj->version, + mobj->banks, idx, i);if (!bank)return -ENOENT ; bank->accepted =1 ;
@@ -281,25 +222,22 @@ fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj,return 0 ; } -#if defined(CONFIG_FWU_MDATA_V1 ) -static void fwu_fill_version_specific_mdata (struct fwu_mdata_object *mobj) -{ -} -#else static void fwu_fill_version_specific_mdata (struct fwu_mdata_object *mobj) {int i;struct fwu_fw_store_desc *fw_desc; -struct fwu_mdata *mdata = mobj->mdata; +struct fwu_mdata_ext *mdata_ext; - mdata->metadata_size = mobj->size; - mdata->desc_offset =sizeof (struct fwu_mdata ); + mdata_ext =fwu_get_fw_mdata_ext (mobj->mdata); + mdata_ext->metadata_size = mobj->size; + mdata_ext->desc_offset =sizeof (struct fwu_mdata ) + +sizeof (struct fwu_mdata_ext );for (i =0 ; i <MAX_BANKS_V2 ; i++) - mdata->bank_state[i] = i < mobj->banks ? -BANK_ACCEPTED :BANK_INVALID ; + mdata_ext->bank_state[i] = i < mobj->banks ? +FWU_BANK_ACCEPTED :FWU_BANK_INVALID ; - fw_desc = (struct fwu_fw_store_desc *)((u8 *)mdata +sizeof (*mdata)); + fw_desc =fwu_get_fw_desc (mobj->mdata); fw_desc->num_banks = mobj->banks; fw_desc->num_images = mobj->images; fw_desc->img_entry_size = sizeof(struct fwu_image_entry) +
@@ -307,7 +245,6 @@ static void fwu_fill_version_specific_mdata(struct fwu_mdata_object *mobj) fw_desc->bank_info_entry_size =sizeof (struct fwu_image_bank_info ); } -#endif /* CONFIG_FWU_MDATA_V1 */ /* Caller must ensure that @uuids[] has @mobj->images entries. */ static int fwu_parse_fill_uuids (struct fwu_mdata_object *mobj,char *uuids[])
@@ -320,7 +257,8 @@ static int fwu_parse_fill_uuids(struct fwu_mdata_object *mobj, char *uuids[]) mdata->active_index = active_bank; mdata->previous_active_index = previous_bank; -fwu_fill_version_specific_mdata (mobj); +if (mdata->version ==2 ) +fwu_fill_version_specific_mdata (mobj);for (i =0 ; i < mobj->images; i++) { ret =fwu_parse_fill_image_uuid (mobj, i, uuids[i]);
Signature · 1 line
2.43.0
Hi Kory,
Thanks for the series.
I have tested the fwumdata tool on a STM32MP257F-EV1 board using metadata with banks containing 3 images, and everything works as expected.
Quoted 9 lines · On Wed, 18 Mar 2026 12:27:54 +0100 Dario Binacchi…
Hi Kory,
Thanks for the series.
I have tested the fwumdata tool on a STM32MP257F-EV1 board using metadata with banks containing 3 images, and everything works as expected.
Tested-by Dario Binacchi <[email protected]>
Thank you.
Ilias, Sughosh any new on this series?
Regards,
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Quoted 11 lines · Kory Maincent
Quoted 8 lines · On Wed, 18 Mar 2026 12:27:54 +0100 Dario Binacchi…
Hi Kory,
Thanks for the series.
I have tested the fwumdata tool on a STM32MP257F-EV1 board using metadata with banks containing 3 images, and everything works as expected.
Quoted 5 lines
Quoted 1 line
Tested-by Dario Binacchi <[email protected]>Thank you.
Ilias, Sughosh any new on this series?
All good from my side. Ilias, can you please send a PR from one of your tree. Thanks.
-sughosh