| Message ID | 20251228151824.25667-5-dario.binacchi@amarulasolutions.com |
|---|---|
| State | New |
| Headers |
Return-Path:
<linux-amarula+bncBCQ4XFG47UFRBTUUYXFAMGQEYHN7IRY@amarulasolutions.com>
X-Original-To: linux-amarula@patchwork.amarulasolutions.com
Delivered-To: linux-amarula@patchwork.amarulasolutions.com
Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com
[209.85.208.71])
by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 907C83FA64
for <linux-amarula@patchwork.amarulasolutions.com>;
Sun, 28 Dec 2025 16:18:39 +0100 (CET)
Received: by mail-ed1-f71.google.com with SMTP id
4fb4d7f45d1cf-64d251b8c5dsf5805620a12.1
for <linux-amarula@patchwork.amarulasolutions.com>;
Sun, 28 Dec 2025 07:18:39 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1766935119; cv=pass;
d=google.com; s=arc-20240605;
b=Y4hPxjlTh2Le9IuQ9GkMgoaHKi/uFcERMHBS47kUaX/UQMR42H9QcuLnDh2OpGKGeT
3AvOA1L9viz216F4mffYor3V/pSfa0u/JZll64GDa5FuPbmmGOFWOUofx2L19+28IjtN
Vkf3StnvmnkBJoV+tb/W8bP2WaFy7ktont2yhQj2SKKLXz7kVyuiB+ZSAdSKJH05Zcd1
LobdYlwJrxKGar12E9k9g+iFQJYcNaydnmkZQ2FUImhvgtHfdiL8pOU0CqxZhIAlFlYn
+Bybtr9KJjndB4sQ8vRY2sitvx6bARWRX/EIyKlo0+fsnrUfV7ZDY66ZJpmu8kFm2JiK
e1Lw==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20240605;
h=list-unsubscribe:list-archive:list-help:list-post:list-id
:mailing-list:precedence:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:dkim-signature;
bh=jWfD1I1Hzq0OrXfdBwOoVa9S/6uyqISNhzVR6amVb6c=;
fh=3+CVHxG3vxO24phRwJLKyLvEeJyNeEPA0+++uYhSJ5k=;
b=KBXS9IvcxjvZCGPLQf6dFONjXxGmFhsh8fwKmb3o0b+EspU5ajIgzD7ElKqL4bKj4M
w1fueOTkPfxl+bWSFymsKVt0OanM/6V4hc8ukQHvjCXE452zdvRRZ4SV9Ju+MpPuSajh
rz7lrGqo6Az1/WqZ2qLsV/XKZRIkglIx+axDKSMEe5P+4bSo3pcHPaPbjqenInTt2+jt
2djZyPf0wL6qgLcr/OLo0/Swm4uegSv7EFen3y8N56aHHAfYdpGiVh0N9xMEwwejJJQU
I+QpNxS4It9qoBr3OfZ34PPt0Fx0g+7CV1ZBI1+QSAYaEm4QGhL3pyZ1MZ4JOLNJUEum
+xPw==;
darn=patchwork.amarulasolutions.com
ARC-Authentication-Results: i=2; mx.google.com;
dkim=pass header.i=@amarulasolutions.com header.s=google
header.b=fXTU2z+W;
spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=dario.binacchi@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=neutral header.i=@amarulasolutions.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=amarulasolutions.com; s=google; t=1766935119; x=1767539919;
darn=patchwork.amarulasolutions.com;
h=list-unsubscribe:list-archive:list-help:list-post:list-id
:mailing-list:precedence:x-original-authentication-results
:x-original-sender:mime-version:references:in-reply-to:message-id
:date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to;
bh=jWfD1I1Hzq0OrXfdBwOoVa9S/6uyqISNhzVR6amVb6c=;
b=jIQUBhY4ET5MRA4iWtE1qjnm+27EBTgUDpKzZk2cZ/7DGpwaQRAI2FFa2Uls/QmAxT
vH9DoJF26y0vrGVPyaiYH9SmuXhe/tih8tukZJ2rUhGC8HSSQIaWmkS5ctPgRf4vEMnD
8vEuPIioaRNiW9lezNg5832I5G+LJP25vz3WY=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1766935119; x=1767539919;
h=list-unsubscribe:list-archive:list-help:list-post
:x-spam-checked-in-group:list-id:mailing-list:precedence
:x-original-authentication-results:x-original-sender:mime-version
:references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg
:x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id
:reply-to;
bh=jWfD1I1Hzq0OrXfdBwOoVa9S/6uyqISNhzVR6amVb6c=;
b=sSPHZA/BkCFLWpBmOwccGSXcZGrVKRjgpnRijZX5pV6VDklLFxJNsEG7SlO2txa2EB
V5OMzcoZ72Ncynj8lTLdqlGYecpyMFMDkcCPa5X3zUcCW5bLTLBfdphp7+nadCi8vQQh
jzTZ+vZG/8WtY6MmtGr1PDzGtXdFOdvyKPurZ7dYOxXkGmhptasXNBnMANAsd7//VYuT
v0TdeNOa++hmvD2NAJu4L/byqJYIJbN8jFXDZjlQei9rCJVD4rMVH2QeCTe4uDX0C/OG
SKmJTJXdD8vWw+QUSpL49V+TjiMVTlECiWICVqBX1bYE19nv9ihKx5DdksWSLfcjVLK6
GXSA==
X-Forwarded-Encrypted: i=2;
AJvYcCX2mFPd8uzudXRFy4dDBJfy7rfSJQotTUIA895bFWx+aaqOE8sM6HSRbmT/SZvjmdbug3hULA2V2nVU8A5S@patchwork.amarulasolutions.com
X-Gm-Message-State: AOJu0YyoftgJ+UWrU0kOkK7TBOrNgBFGtzJk5QyWwqPJrKySdfp89/qH
m6VXjdd7wbUEMfysNyM/LxBQYn2E4hQRqbsY1VJJ7hVV+LvKwvWzxUDzRfQgjKg/KDhs7A==
X-Google-Smtp-Source:
AGHT+IEQ8nkVBPQfOqeophq1v3lUtOPElVOH8fftP47h34EG34y+Vs2akwANXf7zqs7LWvs/+9avCA==
X-Received: by 2002:a05:6402:5188:b0:649:227b:42af with SMTP id
4fb4d7f45d1cf-64b8e82b799mr26842394a12.4.1766935119245;
Sun, 28 Dec 2025 07:18:39 -0800 (PST)
X-BeenThere: linux-amarula@amarulasolutions.com;
h="AWVwgWYC236Z+XP9n3CVXrYT6uyHeAURvLx9i0VhcJ/Afr6Lfg=="
Received: by 2002:a05:6402:304e:20b0:64b:58c2:9ba4 with SMTP id
4fb4d7f45d1cf-64b58c29c42ls907694a12.2.-pod-prod-01-eu; Sun, 28 Dec 2025
07:18:37 -0800 (PST)
X-Received: by 2002:a17:906:fe41:b0:b73:5a2f:2f0e with SMTP id
a640c23a62f3a-b8036ebf4ebmr2839722666b.3.1766935117353;
Sun, 28 Dec 2025 07:18:37 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1766935117; cv=none;
d=google.com; s=arc-20240605;
b=iaunn8pj9qRx27H1H9MpEbIEh8lsDH9UOUvIhxjzonSTtgG1MLtt4Krl4hqxoWNtn8
ykDnloxvZBMWycDXRTJiO0FWLbXyCxSfJWD3WoY4Ng+Ljj+XxsBzAUfIl9dV+jRleksJ
4xzBNCG168Q55o4rptd9hZ1QZhm++efnA7QnM7VNqIk9XX4qVpeWIs1ehBqO/ntAV5I1
e8tcKulgK3Wan7Ce2EGKrw8hq6degpK7vxA7yHXYXNK/esPGrcErX3PqeZam7mVwVcSq
Neh+XGnvXMcUSVhKY+qP5F1Rxa0jX9/3gheIbDSjimSOOUvwheZcLcZ/5XkKxtA2ijx5
raEg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20240605;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:dkim-signature;
bh=IzWNN3kp85CQmQ0rejN0oR/MF5oE71n0kgDVWwkEKm0=;
fh=UhPqHjbj+Iyt9IFhhTCp2++K2JRm1pKr+R6nojngcl4=;
b=MLs7F1QNTdkC7UKvMiBWlMHdwzbqaLIWpKsPVcefwjAhPxftVkfNyL9uiKL4ET7kdA
WUfLKyPuuMowzlsXC0crcBajk80Cb9HKOVUhlWEauFyGm15SC7lcMUnBcakGvoCWyIT4
VpFS1NDAU4cHQrWX72/1XV9j4uB4Esx+78BoQ4mJXBOlNLVPojF8AO6q0yStBF9gjg/Y
vJAS7yM5Ige3GLv4QFlsyRr+PTAW0IIKdfI2E0ITnXGYWovNkkQFfHDfUH2Kddk+2hZY
Xwv/EthyvpROnNqzInyvZlgHs6tqqJUvoITAqy2cG8B0wVehXr48UJLtJQKZKiycGumb
hHEA==;
dara=google.com
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=@amarulasolutions.com header.s=google
header.b=fXTU2z+W;
spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=dario.binacchi@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=neutral header.i=@amarulasolutions.com
Received: from mail-sor-f41.google.com (mail-sor-f41.google.com.
[209.85.220.41])
by mx.google.com with SMTPS id
4fb4d7f45d1cf-64ba1c5da8asor3282734a12.4.2025.12.28.07.18.37
for <linux-amarula@amarulasolutions.com>
(Google Transport Security);
Sun, 28 Dec 2025 07:18:37 -0800 (PST)
Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Gm-Gg: AY/fxX5v7ud1a/kgqSly35CTkPrurk2cLR4Xg2WwQ6jVOjC9R+cLQjFn5V7PSAtpr51
trNvDKQmB1npQvg3kPbB6ZA9ccZmdmerXlmVLihK7kyl3+ilCBLiefbZAJ/QeftvyvejeryX7fR
QpAniazxWT4rKuPmmaEhujaOPvMxpChPCt7mN9lVJT8xZfGbGEbQBqCPVBw3o0uROl+AKfcQf3G
+bvHp4bbJ2W8fS+79QqG0N1ObHWokwyxn9Dp0bO28ASYNQqeWXkOVnC/7mh8MBPv29+US29hvsu
i3zqRZGZZZbgyDrIBam/ixbze4JQWIpjskAG746kZW95qiOrFR3BnoVh+jLlEC2wxeXvkwBRe3X
JdZ/IX5WJS+e04GVnqO2gK1Teddn8mEPQ//65x15ssU8SQMTydRC+tH4szbB2Idb0ZLfaJJF8Bu
spoSU+dvrHS4M5govVJAxF5e5r+FC/nRBFRDu8YOOYlEIQ2oXr8o/rratxc3joj5/dwtuaouW1a
4NMOpIhIpCmjni5gijdQC4O+MIdAPNJvcVTtZ4MRSB9NUZnNRWqw78XKKtKED6sTVgKVKQZ94BE
L7vOTcaO3WI=
X-Received: by 2002:a05:6402:2807:b0:64b:6ebf:b65b with SMTP id
4fb4d7f45d1cf-64b8e82b993mr28404527a12.5.1766935116837;
Sun, 28 Dec 2025 07:18:36 -0800 (PST)
Received: from dario-ThinkPad-P14s-Gen-5.homenet.telecomitalia.it
(host-95-248-31-95.retail.telecomitalia.it. [95.248.31.95])
by smtp.gmail.com with ESMTPSA id
4fb4d7f45d1cf-64b91494cd7sm28502224a12.16.2025.12.28.07.18.34
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sun, 28 Dec 2025 07:18:35 -0800 (PST)
From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
To: u-boot@lists.denx.de
Cc: linux-amarula@amarulasolutions.com,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Daniel Golle <daniel@makrotopia.org>,
E Shattow <e@freeshell.de>,
Jan Kiszka <jan.kiszka@siemens.com>,
Paul HENRYS <paul.henrys_ext@softathome.com>,
Peter Robinson <pbrobinson@gmail.com>,
Raymond Mao <raymondmaoca@gmail.com>,
Shiji Yang <yangshiji66@outlook.com>,
Simon Glass <sjg@chromium.org>,
Tom Rini <trini@konsulko.com>
Subject: [PATCH 4/5] tools: Add dumpfwumdata tool for FWU metadata image
Date: Sun, 28 Dec 2025 16:17:54 +0100
Message-ID: <20251228151824.25667-5-dario.binacchi@amarulasolutions.com>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <20251228151824.25667-1-dario.binacchi@amarulasolutions.com>
References: <20251228151824.25667-1-dario.binacchi@amarulasolutions.com>
MIME-Version: 1.0
X-Original-Sender: dario.binacchi@amarulasolutions.com
X-Original-Authentication-Results: mx.google.com; dkim=pass
header.i=@amarulasolutions.com header.s=google header.b=fXTU2z+W;
spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=dario.binacchi@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=neutral header.i=@amarulasolutions.com
Content-Type: text/plain; charset="UTF-8"
Precedence: list
Mailing-list: list linux-amarula@amarulasolutions.com;
contact linux-amarula+owners@amarulasolutions.com
List-ID: <linux-amarula.amarulasolutions.com>
X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com
X-Google-Group-Id: 476853432473
List-Post:
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/post>,
<mailto:linux-amarula@amarulasolutions.com>
List-Help:
<https://support.google.com/a/amarulasolutions.com/bin/topic.py?topic=25838>,
<mailto:linux-amarula+help@amarulasolutions.com>
List-Archive:
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/>
List-Unsubscribe:
<mailto:googlegroups-manage+476853432473+unsubscribe@googlegroups.com>,
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/subscribe>
|
| Series |
Add dumpfwumdata tool for FWU metadata image
|
|
Commit Message
Dario Binacchi
Dec. 28, 2025, 3:17 p.m. UTC
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.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
tools/Kconfig | 7 +++
tools/Makefile | 4 ++
tools/dumpfwumdata.c | 128 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 139 insertions(+)
create mode 100644 tools/dumpfwumdata.c
Comments
ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi <dario.binacchi@amarulasolutions.com> napsal: > > 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. > > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > --- > > tools/Kconfig | 7 +++ > tools/Makefile | 4 ++ > tools/dumpfwumdata.c | 128 +++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 139 insertions(+) > create mode 100644 tools/dumpfwumdata.c > > diff --git a/tools/Kconfig b/tools/Kconfig > index 652b0f225579..9de7eed1bbbb 100644 > --- a/tools/Kconfig > +++ b/tools/Kconfig > @@ -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 > diff --git a/tools/Makefile b/tools/Makefile > index ae6a30526466..bc105a086927 100644 > --- a/tools/Makefile > +++ b/tools/Makefile > @@ -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 <sughosh.ganu@linaro.org> AuthorDate: Tue Dec 16 11:16:24 2025 +0200 Commit: Tom Rini <trini@konsulko.com> CommitDate: Fri Jan 2 10:28:14 2026 -0600 kbuild: Bump the build system to 6.1 add missing always. > + > mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o > HOSTLDLIBS_mkfwumdata += -luuid > hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata > diff --git a/tools/dumpfwumdata.c b/tools/dumpfwumdata.c > new file mode 100644 > index 000000000000..4965484df1be > --- /dev/null > +++ b/tools/dumpfwumdata.c > @@ -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; > + 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. > + > + 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. > +} > + > +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; > + > + 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. > + > + 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; > +} > -- > 2.43.0 > M
Hello Michal, On Mon, Jan 5, 2026 at 4:40 PM Michal Simek <monstr@monstr.eu> wrote: > > ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi > <dario.binacchi@amarulasolutions.com> napsal: > > > > 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. > > > > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > > --- > > > > tools/Kconfig | 7 +++ > > tools/Makefile | 4 ++ > > tools/dumpfwumdata.c | 128 +++++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 139 insertions(+) > > create mode 100644 tools/dumpfwumdata.c > > > > diff --git a/tools/Kconfig b/tools/Kconfig > > index 652b0f225579..9de7eed1bbbb 100644 > > --- a/tools/Kconfig > > +++ b/tools/Kconfig > > @@ -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 > > diff --git a/tools/Makefile b/tools/Makefile > > index ae6a30526466..bc105a086927 100644 > > --- a/tools/Makefile > > +++ b/tools/Makefile > > @@ -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 <sughosh.ganu@linaro.org> > AuthorDate: Tue Dec 16 11:16:24 2025 +0200 > Commit: Tom Rini <trini@konsulko.com> > CommitDate: Fri Jan 2 10:28:14 2026 -0600 > > kbuild: Bump the build system to 6.1 > > > add missing always. > > > + > > mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o > > HOSTLDLIBS_mkfwumdata += -luuid > > hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata > > diff --git a/tools/dumpfwumdata.c b/tools/dumpfwumdata.c > > new file mode 100644 > > index 000000000000..4965484df1be > > --- /dev/null > > +++ b/tools/dumpfwumdata.c > > @@ -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; > > + 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. > > > + > > + 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. > > > +} > > + > > +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; > > + > > + 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/20251212-feature_fwumdata-v2-0-ad51572fbe79@bootlin.com/. 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 > > > + > > + 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; > > +} > > -- > > 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
On 1/11/26 16:17, Dario Binacchi wrote: > Hello Michal, > > On Mon, Jan 5, 2026 at 4:40 PM Michal Simek <monstr@monstr.eu> wrote: >> >> ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi >> <dario.binacchi@amarulasolutions.com> napsal: >>> >>> 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. >>> >>> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> >>> --- >>> >>> tools/Kconfig | 7 +++ >>> tools/Makefile | 4 ++ >>> tools/dumpfwumdata.c | 128 +++++++++++++++++++++++++++++++++++++++++++ >>> 3 files changed, 139 insertions(+) >>> create mode 100644 tools/dumpfwumdata.c >>> >>> diff --git a/tools/Kconfig b/tools/Kconfig >>> index 652b0f225579..9de7eed1bbbb 100644 >>> --- a/tools/Kconfig >>> +++ b/tools/Kconfig >>> @@ -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 >>> diff --git a/tools/Makefile b/tools/Makefile >>> index ae6a30526466..bc105a086927 100644 >>> --- a/tools/Makefile >>> +++ b/tools/Makefile >>> @@ -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 <sughosh.ganu@linaro.org> >> AuthorDate: Tue Dec 16 11:16:24 2025 +0200 >> Commit: Tom Rini <trini@konsulko.com> >> CommitDate: Fri Jan 2 10:28:14 2026 -0600 >> >> kbuild: Bump the build system to 6.1 >> >> >> add missing always. >> >>> + >>> mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o >>> HOSTLDLIBS_mkfwumdata += -luuid >>> hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata >>> diff --git a/tools/dumpfwumdata.c b/tools/dumpfwumdata.c >>> new file mode 100644 >>> index 000000000000..4965484df1be >>> --- /dev/null >>> +++ b/tools/dumpfwumdata.c >>> @@ -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; >>> + 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. >> >>> + >>> + 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. >> >>> +} >>> + >>> +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; >>> + >>> + 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/20251212-feature_fwumdata-v2-0-ad51572fbe79@bootlin.com/. > 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 To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
On Mon, 12 Jan 2026 10:05:50 +0100 Michal Simek <monstr@monstr.eu> wrote: > On 1/11/26 16:17, Dario Binacchi wrote: > > Hello Michal, > > > > On Mon, Jan 5, 2026 at 4:40 PM Michal Simek <monstr@monstr.eu> wrote: > >> > >> ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi > >> <dario.binacchi@amarulasolutions.com> napsal: > >>> > >>> 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. > >>> > >>> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> ... > >>> +} > >>> + > >>> +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; > >>> + > >>> + 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/20251212-feature_fwumdata-v2-0-ad51572fbe79@bootlin.com/. > > 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. 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,
Hello Kory, On Mon, Jan 12, 2026 at 10:24 AM Kory Maincent <kory.maincent@bootlin.com> wrote: > > On Mon, 12 Jan 2026 10:05:50 +0100 > Michal Simek <monstr@monstr.eu> wrote: > > > On 1/11/26 16:17, Dario Binacchi wrote: > > > Hello Michal, > > > > > > On Mon, Jan 5, 2026 at 4:40 PM Michal Simek <monstr@monstr.eu> wrote: > > >> > > >> ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi > > >> <dario.binacchi@amarulasolutions.com> napsal: > > >>> > > >>> 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. > > >>> > > >>> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > > ... > > > >>> +} > > >>> + > > >>> +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; > > >>> + > > >>> + 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/20251212-feature_fwumdata-v2-0-ad51572fbe79@bootlin.com/. > > > 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. > > 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 > > Regards, > -- > Köry Maincent, Bootlin > Embedded Linux and kernel engineering > https://bootlin.com
On Sat, 17 Jan 2026 12:11:18 +0100 Dario Binacchi <dario.binacchi@amarulasolutions.com> wrote: > Hello Kory, > > On Mon, Jan 12, 2026 at 10:24 AM Kory Maincent > <kory.maincent@bootlin.com> wrote: > > > > On Mon, 12 Jan 2026 10:05:50 +0100 > > Michal Simek <monstr@monstr.eu> wrote: > > > > > On 1/11/26 16:17, Dario Binacchi wrote: > > > > Hello Michal, > > > > > > > > On Mon, Jan 5, 2026 at 4:40 PM Michal Simek <monstr@monstr.eu> wrote: > > > >> > > > >> ne 28. 12. 2025 v 16:19 odesílatel Dario Binacchi > > > >> <dario.binacchi@amarulasolutions.com> napsal: > > > >>> > > > >>> 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. > > > >>> > > > >>> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > > > > ... > > > > > >>> +} > > > >>> + > > > >>> +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; > > > >>> + > > > >>> + 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/20251212-feature_fwumdata-v2-0-ad51572fbe79@bootlin.com/. > > > > 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. > > > > 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? 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,
diff --git a/tools/Kconfig b/tools/Kconfig index 652b0f225579..9de7eed1bbbb 100644 --- a/tools/Kconfig +++ b/tools/Kconfig @@ -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 diff --git a/tools/Makefile b/tools/Makefile index ae6a30526466..bc105a086927 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -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 diff --git a/tools/dumpfwumdata.c b/tools/dumpfwumdata.c new file mode 100644 index 000000000000..4965484df1be --- /dev/null +++ b/tools/dumpfwumdata.c @@ -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; + 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 = '?'; + + printf("bank_state[%d]: %c\n", i, cstate); + } + } +} + +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; + + if (argc < 3) { + print_usage(); + return -EINVAL; + } + + 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; +}