From: Kane-Chen-AS <kane_chen@aspeedtech.com>
This patch introduces a 'drive' property to the Aspeed OTP device,
allowing it to be backed by a block device. Users can now preload
OTP data via QEMU CLI using a block backend.
Example usage:
./qemu-system-arm \
-blockdev driver=file,filename=otpmem.img,node-name=otp \
-global aspeed-otp.drive=otp \
...
If the drive is provided, its content will be loaded as the initial OTP state.
Otherwise, an internal memory buffer will be used.
Signed-off-by: Kane-Chen-AS <kane_chen@aspeedtech.com>
---
hw/nvram/aspeed_otp.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/hw/nvram/aspeed_otp.c b/hw/nvram/aspeed_otp.c
index e41481d9bb..f018c58713 100644
--- a/hw/nvram/aspeed_otp.c
+++ b/hw/nvram/aspeed_otp.c
@@ -9,6 +9,7 @@
#include "qemu/osdep.h"
#include "qemu/log.h"
#include "qapi/error.h"
+#include "system/block-backend-global-state.h"
#include "system/block-backend-io.h"
#include "hw/qdev-properties.h"
#include "hw/nvram/aspeed_otp.h"
@@ -35,13 +36,25 @@ static bool aspeed_otp_init_storage(AspeedOTPState *s, Error **errp)
{
uint32_t *p;
int i, num;
+ uint64_t perm;
+ if (s->blk) {
+ perm = BLK_PERM_CONSISTENT_READ |
+ (blk_supports_write_perm(s->blk) ? BLK_PERM_WRITE : 0);
+ if (blk_set_perm(s->blk, perm, BLK_PERM_ALL, errp) < 0) {
+ return false;
+ }
+ if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
+ error_setg(errp, "Failed to read the initial flash content");
+ return false;
+ }
+ } else {
num = s->size / sizeof(uint32_t);
p = (uint32_t *)s->storage;
for (i = 0; i < num; i++) {
p[i] = (i % 2 == 0) ? 0x00000000 : 0xFFFFFFFF;
}
-
+ }
return true;
}
@@ -75,6 +88,7 @@ static void aspeed_otp_realize(DeviceState *dev, Error **errp)
static const Property aspeed_otp_properties[] = {
DEFINE_PROP_UINT64("size", AspeedOTPState, size, 0),
+ DEFINE_PROP_DRIVE("drive", AspeedOTPState, blk),
};
static void aspeed_otp_class_init(ObjectClass *klass, const void *data)
--
2.43.0
On 7/8/25 07:57, Kane Chen wrote:
> From: Kane-Chen-AS <kane_chen@aspeedtech.com>
>
> This patch introduces a 'drive' property to the Aspeed OTP device,
> allowing it to be backed by a block device. Users can now preload
> OTP data via QEMU CLI using a block backend.
>
> Example usage:
> ./qemu-system-arm \
> -blockdev driver=file,filename=otpmem.img,node-name=otp \
> -global aspeed-otp.drive=otp \
> ...
>
> If the drive is provided, its content will be loaded as the initial OTP state.
> Otherwise, an internal memory buffer will be used.
>
> Signed-off-by: Kane-Chen-AS <kane_chen@aspeedtech.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Thanks,
C.
> ---
> hw/nvram/aspeed_otp.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/hw/nvram/aspeed_otp.c b/hw/nvram/aspeed_otp.c
> index e41481d9bb..f018c58713 100644
> --- a/hw/nvram/aspeed_otp.c
> +++ b/hw/nvram/aspeed_otp.c
> @@ -9,6 +9,7 @@
> #include "qemu/osdep.h"
> #include "qemu/log.h"
> #include "qapi/error.h"
> +#include "system/block-backend-global-state.h"
> #include "system/block-backend-io.h"
> #include "hw/qdev-properties.h"
> #include "hw/nvram/aspeed_otp.h"
> @@ -35,13 +36,25 @@ static bool aspeed_otp_init_storage(AspeedOTPState *s, Error **errp)
> {
> uint32_t *p;
> int i, num;
> + uint64_t perm;
>
> + if (s->blk) {
> + perm = BLK_PERM_CONSISTENT_READ |
> + (blk_supports_write_perm(s->blk) ? BLK_PERM_WRITE : 0);
> + if (blk_set_perm(s->blk, perm, BLK_PERM_ALL, errp) < 0) {
> + return false;
> + }
> + if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
> + error_setg(errp, "Failed to read the initial flash content");
> + return false;
> + }
> + } else {
> num = s->size / sizeof(uint32_t);
> p = (uint32_t *)s->storage;
> for (i = 0; i < num; i++) {
> p[i] = (i % 2 == 0) ? 0x00000000 : 0xFFFFFFFF;
> }
> -
> + }
> return true;
> }
>
> @@ -75,6 +88,7 @@ static void aspeed_otp_realize(DeviceState *dev, Error **errp)
>
> static const Property aspeed_otp_properties[] = {
> DEFINE_PROP_UINT64("size", AspeedOTPState, size, 0),
> + DEFINE_PROP_DRIVE("drive", AspeedOTPState, blk),
> };
>
> static void aspeed_otp_class_init(ObjectClass *klass, const void *data)
Cédric Le Goater <clg@kaod.org> writes:
> On 7/8/25 07:57, Kane Chen wrote:
>> From: Kane-Chen-AS <kane_chen@aspeedtech.com>
>> This patch introduces a 'drive' property to the Aspeed OTP device,
>> allowing it to be backed by a block device. Users can now preload
>> OTP data via QEMU CLI using a block backend.
>> Example usage:
>> ./qemu-system-arm \
>> -blockdev driver=file,filename=otpmem.img,node-name=otp \
>> -global aspeed-otp.drive=otp \
>> ...
>> If the drive is provided, its content will be loaded as the initial
>> OTP state.
>> Otherwise, an internal memory buffer will be used.
>> Signed-off-by: Kane-Chen-AS <kane_chen@aspeedtech.com>
>
>
> Reviewed-by: Cédric Le Goater <clg@redhat.com>
Erm where is this email getting tagged as SPAM? The headers seem to
indicate its clear:
X-Spam_score_int: -39
X-Spam_score: -4.0
X-Spam_bar: ----
X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9,
HEADER_FROM_DIFFERENT_DOMAINS=0.157, RCVD_IN_DNSWL_MED=-2.3,
SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-arm@nongnu.org
X-Mailman-Version: 2.1.29
>
> Thanks,
>
> C.
>
>
>> ---
>> hw/nvram/aspeed_otp.c | 16 +++++++++++++++-
>> 1 file changed, 15 insertions(+), 1 deletion(-)
>> diff --git a/hw/nvram/aspeed_otp.c b/hw/nvram/aspeed_otp.c
>> index e41481d9bb..f018c58713 100644
>> --- a/hw/nvram/aspeed_otp.c
>> +++ b/hw/nvram/aspeed_otp.c
>> @@ -9,6 +9,7 @@
>> #include "qemu/osdep.h"
>> #include "qemu/log.h"
>> #include "qapi/error.h"
>> +#include "system/block-backend-global-state.h"
>> #include "system/block-backend-io.h"
>> #include "hw/qdev-properties.h"
>> #include "hw/nvram/aspeed_otp.h"
>> @@ -35,13 +36,25 @@ static bool aspeed_otp_init_storage(AspeedOTPState *s, Error **errp)
>> {
>> uint32_t *p;
>> int i, num;
>> + uint64_t perm;
>> + if (s->blk) {
>> + perm = BLK_PERM_CONSISTENT_READ |
>> + (blk_supports_write_perm(s->blk) ? BLK_PERM_WRITE : 0);
>> + if (blk_set_perm(s->blk, perm, BLK_PERM_ALL, errp) < 0) {
>> + return false;
>> + }
>> + if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
>> + error_setg(errp, "Failed to read the initial flash content");
>> + return false;
>> + }
>> + } else {
>> num = s->size / sizeof(uint32_t);
>> p = (uint32_t *)s->storage;
>> for (i = 0; i < num; i++) {
>> p[i] = (i % 2 == 0) ? 0x00000000 : 0xFFFFFFFF;
>> }
>> -
>> + }
>> return true;
>> }
>> @@ -75,6 +88,7 @@ static void aspeed_otp_realize(DeviceState *dev,
>> Error **errp)
>> static const Property aspeed_otp_properties[] = {
>> DEFINE_PROP_UINT64("size", AspeedOTPState, size, 0),
>> + DEFINE_PROP_DRIVE("drive", AspeedOTPState, blk),
>> };
>> static void aspeed_otp_class_init(ObjectClass *klass, const void
>> *data)
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
On 7/22/25 12:27, Alex Bennée wrote:
> Cédric Le Goater <clg@kaod.org> writes:
>
>> On 7/8/25 07:57, Kane Chen wrote:
>>> From: Kane-Chen-AS <kane_chen@aspeedtech.com>
>>> This patch introduces a 'drive' property to the Aspeed OTP device,
>>> allowing it to be backed by a block device. Users can now preload
>>> OTP data via QEMU CLI using a block backend.
>>> Example usage:
>>> ./qemu-system-arm \
>>> -blockdev driver=file,filename=otpmem.img,node-name=otp \
>>> -global aspeed-otp.drive=otp \
>>> ...
>>> If the drive is provided, its content will be loaded as the initial
>>> OTP state.
>>> Otherwise, an internal memory buffer will be used.
>>> Signed-off-by: Kane-Chen-AS <kane_chen@aspeedtech.com>
>>
>>
>> Reviewed-by: Cédric Le Goater <clg@redhat.com>
>
> Erm where is this email getting tagged as SPAM? The headers seem to
> indicate its clear:
>
> X-Spam_score_int: -39
> X-Spam_score: -4.0
> X-Spam_bar: ----
> X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9,
> HEADER_FROM_DIFFERENT_DOMAINS=0.157, RCVD_IN_DNSWL_MED=-2.3,
> SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
> X-Spam_action: no action
> X-BeenThere: qemu-arm@nongnu.org
> X-Mailman-Version: 2.1.29
I guess it's my provider (OVH). See below what I received.
C.
X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
Received: from DAG8EX1.mxp5.local (172.16.2.71) by DAG8EX2.mxp5.local
(172.16.2.72) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.44 via Mailbox
Transport; Tue, 8 Jul 2025 07:58:23 +0200
Received: from DAG9EX2.mxp5.local (172.16.2.82) by DAG8EX1.mxp5.local
(172.16.2.71) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.44; Tue, 8 Jul
2025 07:58:23 +0200
Received: from output47.mail.ovh.net (164.132.34.47) by mxplan5.mail.ovh.net
(172.16.2.82) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.44 via Frontend
Transport; Tue, 8 Jul 2025 07:58:23 +0200
Received: from vr27.mail.ovh.net (unknown [10.101.8.27])
by out47.mail.ovh.net (Postfix) with ESMTP id 4bbr4v1fkDz1K9FR
for <clg@kaod.org>; Tue, 8 Jul 2025 05:58:23 +0000 (UTC)
Received: from in79.mail.ovh.net (unknown [10.101.4.79])
by vr27.mail.ovh.net (Postfix) with ESMTP id 4bbr4t0F45zFpd7
for <clg@kaod.org>; Tue, 8 Jul 2025 05:58:22 +0000 (UTC)
Received: from TWMBX01.aspeed.com (mail.aspeedtech.com [211.20.114.72])
by in79.mail.ovh.net (Postfix) with ESMTPS id 4bbr4s4RcFz6dtBC
for <clg@kaod.org>; Tue, 8 Jul 2025 05:58:21 +0000 (UTC)
Authentication-Results: mx.mail.ovh.net;
arc=none (no signatures found);
dkim=none (no signatures found);
dmarc=pass policy.published-domain-policy=quarantine policy.applied-disposition=none policy.evaluated-disposition=none (p=quarantine,d=none,d.eval=none) policy.policy-from=p header.from=aspeedtech.com;
spf=pass smtp.mailfrom=kane_chen@aspeedtech.com smtp.helo=TWMBX01.aspeed.com;
x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES256-GCM-SHA384 smtp.bits=256
Received-SPF: Fail (DAG8EX1.mxp5.local: domain of kane_chen@aspeedtech.com
does not designate 164.132.34.47 as permitted sender)
receiver=DAG8EX1.mxp5.local; client-ip=164.132.34.47;
helo=output47.mail.ovh.net;
Received-SPF: pass
(aspeedtech.com: 211.20.114.72 is authorized to use 'kane_chen@aspeedtech.com' in 'mfrom' identity (mechanism 'ip4:211.20.114.72' matched))
receiver=in79.mail.ovh.net;
identity=mailfrom;
envelope-from="kane_chen@aspeedtech.com";
helo=TWMBX01.aspeed.com;
client-ip=211.20.114.72
Received: from TWMBX01.aspeed.com (192.168.0.62) by TWMBX01.aspeed.com
(192.168.0.62) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Tue, 8 Jul
2025 13:58:10 +0800
Received: from mail.aspeedtech.com (192.168.10.10) by TWMBX01.aspeed.com
(192.168.0.62) with Microsoft SMTP Server id 15.2.1748.10 via Frontend
Transport; Tue, 8 Jul 2025 13:58:10 +0800
From: Kane Chen <kane_chen@aspeedtech.com>
To: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@kaod.org>, Peter Maydell
<peter.maydell@linaro.org>, Steven Lee <steven_lee@aspeedtech.com>, Troy Lee
<leetroy@gmail.com>, Jamin Lin <jamin_lin@aspeedtech.com>, Andrew Jeffery
<andrew@codeconstruct.com.au>, Joel Stanley <joel@jms.id.au>, "open
list:ASPEED BMCs" <qemu-arm@nongnu.org>, "open list:All patches CC here"
<qemu-devel@nongnu.org>
CC: <troy_lee@aspeedtech.com>, Kane-Chen-AS <kane_chen@aspeedtech.com>
Subject: [SPAM] [PATCH v4 0/5] ASPEED OTP QEMU model: block backend, machine alias, SoC integration
Date: Tue, 8 Jul 2025 13:57:52 +0800
Message-ID: <20250708055810.2868680-1-kane_chen@aspeedtech.com>
X-Mailer: git-send-email 2.43.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-OVH-Remote: 211.20.114.72 (mail.aspeedtech.com)
X-Ovh-Tracer-Id: 12933493708818734458
X-VR-SPAMSTATE: SPAM
X-VR-SPAMSCORE: 200
X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdeffeeklecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenogfuphgrmhfkphculdeftddtmdenucfjughrpefhvfevufffkffoggfgtgesthekredtredttdenucfhrhhomhepmfgrnhgvucevhhgvnhcuoehkrghnvggptghhvghnsegrshhpvggvughtvggthhdrtghomheqnecuggftrfgrthhtvghrnhepgeeggfdvuddtgfegkefhudetjefftdefkefhhedtkeekffegveehgfeiheevvefhnecukfhppedvuddurddvtddruddugedrjedvnecuufhprghmkfhppedvuddurddvtddruddugedrjedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdduuddrvddtrdduudegrdejvddphhgvlhhopehtfihmsgigtddurdgrshhpvggvugdrtghomhdpmhgrihhlfhhrohhmpehkrghnvggptghhvghnsegrshhpvggvughtvggthhdrtghomhdpnhgspghrtghpthhtohepuddprhgtphhtthhopegtlhhgsehkrghougdrohhrghdpoffvtefjohhsthepvhhrvdejmgdpughkihhmpehnohhnvggmpdhsphhfpehprghsshgmpdgumhgrrhgtpehprghsshgmpdhrvghvkffrpehmrghilhdrrghsphgvvgguthgvtghhrdgtohhmmgdpghgvohfkrfepvfgh
X-Ovh-Spam-Status: SPAM
X-Ovh-Spam-Reason: vr: SPAM; dkim: disabled; spf: disabled
X-Ovh-Message-Type: SPAM
X-Ovh-Exchange-Junk: True
X-Spam-Tag: YES
Return-Path: kane_chen@aspeedtech.com
X-MS-Exchange-Organization-Network-Message-Id: 126a28f3-a563-4c49-b5da-08ddbde472e1
X-MS-Exchange-Organization-PRD: aspeedtech.com
X-MS-Exchange-Organization-SenderIdResult: Fail
X-MS-Exchange-Organization-AVStamp-Enterprise: 1.0
X-MS-Exchange-ABP-GUID: bd2a0b77-ce4f-4d81-a151-b15427a5e809
X-Ovh-Tracer-GUID: 51d3ce0b-f2d1-4f5a-a08a-a00eb1ad14da
X-MS-Exchange-Organization-SCL: 9
X-MS-Exchange-Organization-AuthSource: DAG9EX2.mxp5.local
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Transport-EndToEndLatency: 00:00:00.5736284
X-MS-Exchange-Processed-By-BccFoldering: 15.01.2507.044
MIME-Version: 1.0
From: Kane-Chen-AS <kane_chen@aspeedtech.com>
© 2016 - 2026 Red Hat, Inc.