Skip to contentSkip to conversation

aspeed: OTP model, SBC integration, tests, and docs

PATCH In review Kane Chen via 3 participants 20 messages Aug 12, 2025 – Sep 2, 2025

Subsystems (2)

v5 of 6 In review Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover aspeed: OTP model, SBC integration, tests, and docs

From: Kane-Chen-AS <[email protected]>

This patch series extends the QEMU model for the ASPEED OTP (One-Time Programmable) memory device with block backend support and tighter integration with the SoC and machine configuration.

The OTP model simulates a simple fuse array used in ASPEED SoCs for secure boot, configuration, key storage, and user-programmable data. The updated model adds support for loading initial OTP content from a file via the QEMU CLI.

Example usage:

  ./qemu-system-arm \
    -machine ast2600-evb \
    -blockdev driver=file,filename=otpmem.img,node-name=otp \
    -global aspeed-otp.drive=otp \
    ...

Any feedback or suggestions are appreciated!

Kane
---

ChangeLog
---------
v5:
- Add OTP programming semantics and tracing
- Integrate OTP into AST1030 SoC
- Add CAMP2 register support for reading both DWORDs of OTP data entries
- Handle voltage mode write commands to avoid misreporting valid requests as "Unknown command"
- Add functional test to verify firmware boot with a pre-configured OTP image
- Add documentation for OTP memory options in QEMU

v4:
- Add a 'drive' property to allow backing OTP data with a block device
- Expose a machine parameter (-machine otpmem=XXX) for convenient aliasing of the OTP drive via QOM path

v3:
- Switched to object_property_set_int() for setting "size"
- Simplified qdev_realize() error handling by passing errp directly
- Added "drive" property to OTP model for future extensibility

v2:
- Rename device from 'aspeed_otpmem' to 'aspeed_otp' and move it to hw/nvram/
- Move OTP device realization from instance_init to the realize function
- Improve error logging with qemu_log_mask() and remove unused error propagation

v1:
- Initial version

---

Kane-Chen-AS (10):
hw/nvram/aspeed_otp: Add ASPEED OTP memory device model hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC hw/arm: Integrate ASPEED OTP memory support into AST2600 SoCs hw/nvram/aspeed_otp: Add 'drive' property to support block backend hw/nvram/aspeed_otp: Add OTP programming semantics and tracing hw/arm: Integrate ASPEED OTP memory support into AST1030 SoCs hw/misc/aspeed_sbc: Add CAMP2 support for OTP data reads hw/misc/aspeed_sbc: Handle OTP write command for voltage mode
registers
tests/function/aspeed: Add OTP functional test docs/system/arm/aspeed: Document OTP memory options

 docs/system/arm/aspeed.rst              |  31 ++++
 include/hw/misc/aspeed_sbc.h            |   6 +
 include/hw/nvram/aspeed_otp.h           |  33 ++++
 hw/arm/aspeed_ast10x0.c                 |   2 +-
 hw/arm/aspeed_ast2600.c                 |   2 +-
 hw/misc/aspeed_sbc.c                    | 196 ++++++++++++++++++++++++
 hw/nvram/aspeed_otp.c                   | 190 +++++++++++++++++++++++
 hw/misc/trace-events                    |   6 +
 hw/nvram/meson.build                    |   4 +
 hw/nvram/trace-events                   |   5 +
 tests/functional/meson.build            |   2 +
 tests/functional/test_arm_aspeed_otp.py |  55 +++++++
 12 files changed, 530 insertions(+), 2 deletions(-)
 create mode 100644 include/hw/nvram/aspeed_otp.h
 create mode 100644 hw/nvram/aspeed_otp.c
 create mode 100644 tests/functional/test_arm_aspeed_otp.py
Signature · 1 line
2.43.0
#1 lore raw

PATCH v5 1/10 hw/nvram/aspeed_otp: Add ASPEED OTP memory device model

From: Kane-Chen-AS <[email protected]>

Introduce a QEMU device model for ASPEED's One-Time Programmable (OTP) memory.

This model simulates a word-addressable OTP region used for secure fuse storage. The OTP memory can operate with an internal memory buffer.

The OTP model provides a memory-like interface through a dedicated AddressSpace, allowing other device models (e.g., SBC) to issue transactions as if accessing a memory-mapped region.

---
 include/hw/nvram/aspeed_otp.h | 33 ++++++++++++
 hw/nvram/aspeed_otp.c         | 99 +++++++++++++++++++++++++++++++++++
 hw/nvram/meson.build          |  4 ++
 3 files changed, 136 insertions(+)
 create mode 100644 include/hw/nvram/aspeed_otp.h
 create mode 100644 hw/nvram/aspeed_otp.c
include/hw/nvram/aspeed_otp.h new file +33 -0
new file mode 100644
index 0000000000..3752353860
@@ -0,0 +1,33 @@
+/*
+ *  ASPEED OTP (One-Time Programmable) memory
+ *
+ *  Copyright (C) 2025 Aspeed
+ *
+ *  SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef ASPEED_OTP_H
+#define ASPEED_OTP_H
+
+#include "system/memory.h"
+#include "hw/block/block.h"
+#include "system/address-spaces.h"
+
+#define TYPE_ASPEED_OTP "aspeed-otp"
+OBJECT_DECLARE_SIMPLE_TYPE(AspeedOTPState, ASPEED_OTP)
+
+typedef struct AspeedOTPState {
+    DeviceState parent_obj;
+
+    BlockBackend *blk;
+
+    uint64_t size;
+
+    AddressSpace as;
+
+    MemoryRegion mmio;
+
+    uint8_t *storage;
+} AspeedOTPState;
+
+#endif /* ASPEED_OTP_H */
hw/nvram/aspeed_otp.c new file +99 -0

99 lines not on this page · raw message

hw/nvram/meson.build +4 -0
index 10f3639db6..b66f23605b 100644
@@ -19,3 +19,7 @@ system_ss.add(when: 'CONFIG_XLNX_BBRAM', if_true: files('xlnx-bbram.c'))
 
 specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))
 specific_ss.add(when: 'CONFIG_ACPI', if_true: files('fw_cfg-acpi.c'))
+
+system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files(
+  'aspeed_otp.c',
+  ))
\ No newline at end of file
Signature · 1 line
2.43.0
#2 lore raw

PATCH v5 2/10 hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC

In reply to Kane Chen via

From: Kane-Chen-AS <[email protected]>

This patch connects the aspeed.otp device to the ASPEED Secure Boot Controller (SBC) model. It implements OTP memory access via the SBC's command interface and enables emulation of secure fuse programming flows.

The following OTP commands are supported:
- READ: reads a 32-bit word from OTP memory into internal registers
- PROG: programs a 32-bit word value to the specified OTP address

Trace events are added to observe read/program operations and command handling flow.

---
 include/hw/misc/aspeed_sbc.h |   5 ++
 hw/misc/aspeed_sbc.c         | 111 +++++++++++++++++++++++++++++++++++
 hw/misc/trace-events         |   5 ++
 3 files changed, 121 insertions(+)
include/hw/misc/aspeed_sbc.h +5 -0
index 405e6782b9..0c2746d392 100644
@@ -10,6 +10,7 @@
 #define ASPEED_SBC_H
 
 #include "hw/sysbus.h"
+#include "hw/nvram/aspeed_otp.h"
 
 #define TYPE_ASPEED_SBC "aspeed.sbc"
 #define TYPE_ASPEED_AST2600_SBC TYPE_ASPEED_SBC "-ast2600"
@@ -36,10 +37,14 @@ struct AspeedSBCState {
     MemoryRegion iomem;
 
     uint32_t regs[ASPEED_SBC_NR_REGS];
+
+    AspeedOTPState otp;
 };
 
 struct AspeedSBCClass {
     SysBusDeviceClass parent_class;
+
+    bool has_otp;
 };
 
 #endif /* ASPEED_SBC_H */
hw/misc/aspeed_sbc.c +111 -0

154 lines not on this page · raw message

hw/misc/trace-events +5 -0
index e3f64c0ff6..9e05b82f37 100644
@@ -90,6 +90,11 @@ slavio_sysctrl_mem_readl(uint32_t ret) "Read system control 0x%08x"
 slavio_led_mem_writew(uint32_t val) "Write diagnostic LED 0x%04x"
 slavio_led_mem_readw(uint32_t ret) "Read diagnostic LED 0x%04x"
 
+# aspeed_sbc.c
+aspeed_sbc_handle_cmd(uint32_t cmd, uint32_t addr, bool ret) "Handling command 0x%" PRIx32 " for OTP addr 0x%" PRIx32 " Result: %d"
+aspeed_sbc_otp_read(uint32_t addr, uint32_t value) "OTP Memory read: addr 0x%" PRIx32 " value 0x%" PRIx32
+aspeed_sbc_otp_prog(uint32_t addr, uint32_t value) "OTP Memory write: addr 0x%" PRIx32 " value 0x%" PRIx32
+
 # aspeed_scu.c
 aspeed_scu_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32
 aspeed_scu_read(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32
Signature · 1 line
2.43.0
#3 lore raw

PATCH v5 3/10 hw/arm: Integrate ASPEED OTP memory support into AST2600 SoCs

In reply to Kane Chen via

From: Kane-Chen-AS <[email protected]>

The has_otp attribute is enabled in the SBC subclasses for AST2600 to control the presence of OTP support per SoC type.

---
 hw/arm/aspeed_ast2600.c | 2 +-
 hw/misc/aspeed_sbc.c    | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
hw/arm/aspeed_ast2600.c +1 -1
index d12707f0ab..59ffd41a4a 100644
@@ -261,7 +261,7 @@ static void aspeed_soc_ast2600_init(Object *obj)
 
     object_initialize_child(obj, "i3c", &s->i3c, TYPE_ASPEED_I3C);
 
-    object_initialize_child(obj, "sbc", &s->sbc, TYPE_ASPEED_SBC);
+    object_initialize_child(obj, "sbc", &s->sbc, TYPE_ASPEED_AST2600_SBC);
 
     object_initialize_child(obj, "iomem", &s->iomem, TYPE_UNIMPLEMENTED_DEVICE);
     object_initialize_child(obj, "video", &s->video, TYPE_UNIMPLEMENTED_DEVICE);
hw/misc/aspeed_sbc.c +2 -0
index 46a038337c..b56a8b7678 100644
@@ -273,8 +273,10 @@ static const TypeInfo aspeed_sbc_info = {
 static void aspeed_ast2600_sbc_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    AspeedSBCClass *sc = ASPEED_SBC_CLASS(klass);
 
     dc->desc = "AST2600 Secure Boot Controller";
+    sc->has_otp = true;
 }
 
 static const TypeInfo aspeed_ast2600_sbc_info = {
Signature · 1 line
2.43.0
#4 lore raw

PATCH v5 4/10 hw/nvram/aspeed_otp: Add 'drive' property to support block backend

In reply to Kane Chen via

From: Kane-Chen-AS <[email protected]>

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.

---
 hw/nvram/aspeed_otp.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
hw/nvram/aspeed_otp.c +14 -1
index e5b7ca9676..abb3731823 100644
@@ -35,13 +35,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 +87,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)
Signature · 1 line
2.43.0
#5 lore raw

PATCH v5 5/10 hw/nvram/aspeed_otp: Add OTP programming semantics and tracing

In reply to Kane Chen via

From: Kane-Chen-AS <[email protected]>

Implement correct OTP programming behavior for Aspeed OTP:
- Support read-modify-write flow with one-way bit programming:
* prog_bit uses 0s as the "to-be-programmed" mask.
* Even-indexed words: 0->1, odd-indexed words: 1->0.
* Reject non-programmable requests and log conflicts.
- Enable unaligned accesses in MemoryRegionOps.
Since each OTP address maps to a 1DW (4B) or 2DW (8B) block in the backing store, upper-layer accesses may be unaligned to block boundaries.

This matches the irreversible, word-parity-dependent programming rules of Aspeed SoCs and exposes changes via QEMU trace events.

---
 hw/nvram/aspeed_otp.c | 80 ++++++++++++++++++++++++++++++++++++++++++-
 hw/nvram/trace-events |  5 +++
 2 files changed, 84 insertions(+), 1 deletion(-)
hw/nvram/aspeed_otp.c +79 -1
index abb3731823..66b2bfea28 100644
@@ -12,6 +12,7 @@
 #include "system/block-backend.h"
 #include "hw/qdev-properties.h"
 #include "hw/nvram/aspeed_otp.h"
+#include "hw/nvram/trace.h"
 
 static uint64_t aspeed_otp_read(void *opaque, hwaddr offset, unsigned size)
 {
@@ -23,12 +24,87 @@ static uint64_t aspeed_otp_read(void *opaque, hwaddr offset, unsigned size)
     return val;
 }
 
+static bool valid_program_data(uint32_t otp_addr,
+                                 uint32_t value, uint32_t prog_bit)
+{
+    uint32_t programmed_bits, has_programmable_bits;
+    bool is_odd = otp_addr & 1;
+
+    /*
+     * prog_bit uses 0s to indicate target bits to program:
+     *   - if OTP word is even-indexed, programmed bits flip 0->1
+     *   - if odd, bits flip 1->0
+     * Bit programming is one-way only and irreversible.
+     */
+    if (is_odd) {
+        programmed_bits = ~value & prog_bit;
+    } else {
+        programmed_bits = value & (~prog_bit);
+    }
+
+    /* If any bit can be programmed, accept the request */
+    has_programmable_bits = value ^ (~prog_bit);
+
+    if (programmed_bits) {
+        trace_aspeed_otp_prog_conflict(otp_addr, programmed_bits);
+        for (int i = 0; i < 32; ++i) {
+            if (programmed_bits & (1U << i)) {
+                trace_aspeed_otp_prog_bit(i);
+            }
+        }
+    }
+
+    return has_programmable_bits != 0;
+}
+
+static bool program_otpmem_data(void *opaque, uint32_t otp_addr,
+                             uint32_t prog_bit, uint32_t *value)
+{
+    AspeedOTPState *s = opaque;
+    bool is_odd = otp_addr & 1;
+    uint32_t otp_offset = otp_addr << 2;
+
+    memcpy(value, s->storage + otp_offset, sizeof(uint32_t));
+
+    if (!valid_program_data(otp_addr, *value, prog_bit)) {
+        return false;
+    }
+
+    if (is_odd) {
+        *value &= ~prog_bit;
+    } else {
+        *value |= ~prog_bit;
+    }
+
+    return true;
+}
+
 static void aspeed_otp_write(void *opaque, hwaddr otp_addr,
                                 uint64_t val, unsigned size)
 {
     AspeedOTPState *s = opaque;
+    uint32_t otp_offset, value;
 
-    memcpy(s->storage + otp_addr, &val, size);
+    if (!program_otpmem_data(s, otp_addr, val, &value)) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: Failed to program data, value = %x, bit = %lx\n",
+                      __func__, value, val);
+        return;
+    }
+
+    otp_offset = otp_addr << 2;
+    memcpy(s->storage + otp_offset, &value, size);
+
+    if (s->blk) {
+        if (blk_pwrite(s->blk, otp_offset, size, &value, 0) < 0) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "%s: Failed to write %x to %x\n",
+                          __func__, value, otp_offset);
+
+            return;
+        }
+    }
+    trace_aspeed_otp_prog(otp_offset, val, value);
 }
 
 static bool aspeed_otp_init_storage(AspeedOTPState *s, Error **errp)
@@ -63,6 +139,8 @@ static const MemoryRegionOps aspeed_otp_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
     .valid.min_access_size = 1,
     .valid.max_access_size = 4,
+    .valid.unaligned = true,
+    .impl.unaligned = true
 };
 
 static void aspeed_otp_realize(DeviceState *dev, Error **errp)
hw/nvram/trace-events +5 -0
index 5e33b24d47..7084bf70d3 100644
@@ -1,5 +1,10 @@
 # See docs/devel/tracing.rst for syntax documentation.
 
+# aspeed_otp.c
+aspeed_otp_prog(uint32_t addr, uint32_t prog_value, uint32_t value) "OTP Memory program: addr 0x%" PRIx32 " prog_value 0x%" PRIx32 " value 0x%" PRIx32
+aspeed_otp_prog_conflict(uint32_t addr, uint32_t bits) "Conflict at addr=0x%x, bits=0x%08x"
+aspeed_otp_prog_bit(int bit) "Programmed bit %d"
+
 # ds1225y.c
 nvram_read(uint32_t addr, uint32_t ret) "read addr %d: 0x%02x"
 nvram_write(uint32_t addr, uint32_t old, uint32_t val) "write addr %d: 0x%02x -> 0x%02x"
Signature · 1 line
2.43.0
Reviewed-by on v5 5/10
#6 lore raw

Re: [SPAM] [PATCH v5 05/10] hw/nvram/aspeed_otp: Add OTP programming semantics and tracing

Quoted 12 lines · Kane Chen

From: Kane-Chen-AS <[email protected]>

Implement correct OTP programming behavior for Aspeed OTP:
- Support read-modify-write flow with one-way bit programming:
* prog_bit uses 0s as the "to-be-programmed" mask.
* Even-indexed words: 0->1, odd-indexed words: 1->0.
* Reject non-programmable requests and log conflicts.
- Enable unaligned accesses in MemoryRegionOps.
Since each OTP address maps to a 1DW (4B) or 2DW (8B) block in the backing store, upper-layer accesses may be unaligned to block boundaries.

Quoted 4 lines

This matches the irreversible, word-parity-dependent programming rules of Aspeed SoCs and exposes changes via QEMU trace events.

Thanks,

C.

Quoted 130 lines
---
  hw/nvram/aspeed_otp.c | 80 ++++++++++++++++++++++++++++++++++++++++++-
  hw/nvram/trace-events |  5 +++
  2 files changed, 84 insertions(+), 1 deletion(-)
hw/nvram/aspeed_otp.c +79 -1
index abb3731823..66b2bfea28 100644
@@ -12,6 +12,7 @@
  #include "system/block-backend.h"
  #include "hw/qdev-properties.h"
  #include "hw/nvram/aspeed_otp.h"
+#include "hw/nvram/trace.h"
 
  static uint64_t aspeed_otp_read(void *opaque, hwaddr offset, unsigned size)
  {
@@ -23,12 +24,87 @@ static uint64_t aspeed_otp_read(void *opaque, hwaddr offset, unsigned size)
      return val;
  }
 
+static bool valid_program_data(uint32_t otp_addr,
+                                 uint32_t value, uint32_t prog_bit)
+{
+    uint32_t programmed_bits, has_programmable_bits;
+    bool is_odd = otp_addr & 1;
+
+    /*
+     * prog_bit uses 0s to indicate target bits to program:
+     *   - if OTP word is even-indexed, programmed bits flip 0->1
+     *   - if odd, bits flip 1->0
+     * Bit programming is one-way only and irreversible.
+     */
+    if (is_odd) {
+        programmed_bits = ~value & prog_bit;
+    } else {
+        programmed_bits = value & (~prog_bit);
+    }
+
+    /* If any bit can be programmed, accept the request */
+    has_programmable_bits = value ^ (~prog_bit);
+
+    if (programmed_bits) {
+        trace_aspeed_otp_prog_conflict(otp_addr, programmed_bits);
+        for (int i = 0; i < 32; ++i) {
+            if (programmed_bits & (1U << i)) {
+                trace_aspeed_otp_prog_bit(i);
+            }
+        }
+    }
+
+    return has_programmable_bits != 0;
+}
+
+static bool program_otpmem_data(void *opaque, uint32_t otp_addr,
+                             uint32_t prog_bit, uint32_t *value)
+{
+    AspeedOTPState *s = opaque;
+    bool is_odd = otp_addr & 1;
+    uint32_t otp_offset = otp_addr << 2;
+
+    memcpy(value, s->storage + otp_offset, sizeof(uint32_t));
+
+    if (!valid_program_data(otp_addr, *value, prog_bit)) {
+        return false;
+    }
+
+    if (is_odd) {
+        *value &= ~prog_bit;
+    } else {
+        *value |= ~prog_bit;
+    }
+
+    return true;
+}
+
  static void aspeed_otp_write(void *opaque, hwaddr otp_addr,
                                  uint64_t val, unsigned size)
  {
      AspeedOTPState *s = opaque;
+    uint32_t otp_offset, value;
 
-    memcpy(s->storage + otp_addr, &val, size);
+    if (!program_otpmem_data(s, otp_addr, val, &value)) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: Failed to program data, value = %x, bit = %lx\n",
+                      __func__, value, val);
+        return;
+    }
+
+    otp_offset = otp_addr << 2;
+    memcpy(s->storage + otp_offset, &value, size);
+
+    if (s->blk) {
+        if (blk_pwrite(s->blk, otp_offset, size, &value, 0) < 0) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "%s: Failed to write %x to %x\n",
+                          __func__, value, otp_offset);
+
+            return;
+        }
+    }
+    trace_aspeed_otp_prog(otp_offset, val, value);
  }
 
  static bool aspeed_otp_init_storage(AspeedOTPState *s, Error **errp)
@@ -63,6 +139,8 @@ static const MemoryRegionOps aspeed_otp_ops = {
      .endianness = DEVICE_LITTLE_ENDIAN,
      .valid.min_access_size = 1,
      .valid.max_access_size = 4,
+    .valid.unaligned = true,
+    .impl.unaligned = true
  };
 
  static void aspeed_otp_realize(DeviceState *dev, Error **errp)
hw/nvram/trace-events +5 -0
index 5e33b24d47..7084bf70d3 100644
@@ -1,5 +1,10 @@
  # See docs/devel/tracing.rst for syntax documentation.
 
+# aspeed_otp.c
+aspeed_otp_prog(uint32_t addr, uint32_t prog_value, uint32_t value) "OTP Memory program: addr 0x%" PRIx32 " prog_value 0x%" PRIx32 " value 0x%" PRIx32
+aspeed_otp_prog_conflict(uint32_t addr, uint32_t bits) "Conflict at addr=0x%x, bits=0x%08x"
+aspeed_otp_prog_bit(int bit) "Programmed bit %d"
+
  # ds1225y.c
  nvram_read(uint32_t addr, uint32_t ret) "read addr %d: 0x%02x"
  nvram_write(uint32_t addr, uint32_t old, uint32_t val) "write addr %d: 0x%02x -> 0x%02x"
#7 lore raw

PATCH v5 6/10 hw/arm: Integrate ASPEED OTP memory support into AST1030 SoCs

In reply to Kane Chen via

From: Kane-Chen-AS <[email protected]>

The has_otp attribute is enabled in the SBC subclasses for AST1030 to control the presence of OTP support per SoC type.

---
 include/hw/misc/aspeed_sbc.h |  1 +
 hw/arm/aspeed_ast10x0.c      |  2 +-
 hw/misc/aspeed_sbc.c         | 16 ++++++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
include/hw/misc/aspeed_sbc.h +1 -0
index 0c2746d392..7d640a022e 100644
@@ -14,6 +14,7 @@
 
 #define TYPE_ASPEED_SBC "aspeed.sbc"
 #define TYPE_ASPEED_AST2600_SBC TYPE_ASPEED_SBC "-ast2600"
+#define TYPE_ASPEED_AST10X0_SBC TYPE_ASPEED_SBC "-ast10x0"
 OBJECT_DECLARE_TYPE(AspeedSBCState, AspeedSBCClass, ASPEED_SBC)
 
 #define ASPEED_SBC_NR_REGS (0x93c >> 2)
hw/arm/aspeed_ast10x0.c +1 -1
index e6e1ee63c1..c446e70b24 100644
@@ -154,7 +154,7 @@ static void aspeed_soc_ast1030_init(Object *obj)
 
     object_initialize_child(obj, "peci", &s->peci, TYPE_ASPEED_PECI);
 
-    object_initialize_child(obj, "sbc", &s->sbc, TYPE_ASPEED_SBC);
+    object_initialize_child(obj, "sbc", &s->sbc, TYPE_ASPEED_AST10X0_SBC);
 
     for (i = 0; i < sc->wdts_num; i++) {
         snprintf(typename, sizeof(typename), "aspeed.wdt-%s", socname);
hw/misc/aspeed_sbc.c +16 -0
index b56a8b7678..052c70fd42 100644
@@ -285,9 +285,25 @@ static const TypeInfo aspeed_ast2600_sbc_info = {
     .class_init = aspeed_ast2600_sbc_class_init,
 };
 
+static void aspeed_ast10x0_sbc_class_init(ObjectClass *klass, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    AspeedSBCClass *sc = ASPEED_SBC_CLASS(klass);
+
+    dc->desc = "AST10X0 Secure Boot Controller";
+    sc->has_otp = true;
+}
+
+static const TypeInfo aspeed_ast10x0_sbc_info = {
+    .name = TYPE_ASPEED_AST10X0_SBC,
+    .parent = TYPE_ASPEED_SBC,
+    .class_init = aspeed_ast10x0_sbc_class_init,
+};
+
 static void aspeed_sbc_register_types(void)
 {
     type_register_static(&aspeed_ast2600_sbc_info);
+    type_register_static(&aspeed_ast10x0_sbc_info);
     type_register_static(&aspeed_sbc_info);
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v5 6/10
#8 lore raw

Re: [SPAM] [PATCH v5 06/10] hw/arm: Integrate ASPEED OTP memory support into AST1030 SoCs

Quoted 6 lines · Kane Chen

From: Kane-Chen-AS <[email protected]>

The has_otp attribute is enabled in the SBC subclasses for AST1030 to control the presence of OTP support per SoC type.

Thanks,

C.

Quoted 61 lines
---
  include/hw/misc/aspeed_sbc.h |  1 +
  hw/arm/aspeed_ast10x0.c      |  2 +-
  hw/misc/aspeed_sbc.c         | 16 ++++++++++++++++
  3 files changed, 18 insertions(+), 1 deletion(-)
include/hw/misc/aspeed_sbc.h +1 -0
index 0c2746d392..7d640a022e 100644
@@ -14,6 +14,7 @@
 
  #define TYPE_ASPEED_SBC "aspeed.sbc"
  #define TYPE_ASPEED_AST2600_SBC TYPE_ASPEED_SBC "-ast2600"
+#define TYPE_ASPEED_AST10X0_SBC TYPE_ASPEED_SBC "-ast10x0"
  OBJECT_DECLARE_TYPE(AspeedSBCState, AspeedSBCClass, ASPEED_SBC)
 
  #define ASPEED_SBC_NR_REGS (0x93c >> 2)
hw/arm/aspeed_ast10x0.c +1 -1
index e6e1ee63c1..c446e70b24 100644
@@ -154,7 +154,7 @@ static void aspeed_soc_ast1030_init(Object *obj)
 
      object_initialize_child(obj, "peci", &s->peci, TYPE_ASPEED_PECI);
 
-    object_initialize_child(obj, "sbc", &s->sbc, TYPE_ASPEED_SBC);
+    object_initialize_child(obj, "sbc", &s->sbc, TYPE_ASPEED_AST10X0_SBC);
 
      for (i = 0; i < sc->wdts_num; i++) {
          snprintf(typename, sizeof(typename), "aspeed.wdt-%s", socname);
hw/misc/aspeed_sbc.c +16 -0
index b56a8b7678..052c70fd42 100644
@@ -285,9 +285,25 @@ static const TypeInfo aspeed_ast2600_sbc_info = {
      .class_init = aspeed_ast2600_sbc_class_init,
  };
 
+static void aspeed_ast10x0_sbc_class_init(ObjectClass *klass, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    AspeedSBCClass *sc = ASPEED_SBC_CLASS(klass);
+
+    dc->desc = "AST10X0 Secure Boot Controller";
+    sc->has_otp = true;
+}
+
+static const TypeInfo aspeed_ast10x0_sbc_info = {
+    .name = TYPE_ASPEED_AST10X0_SBC,
+    .parent = TYPE_ASPEED_SBC,
+    .class_init = aspeed_ast10x0_sbc_class_init,
+};
+
  static void aspeed_sbc_register_types(void)
  {
      type_register_static(&aspeed_ast2600_sbc_info);
+    type_register_static(&aspeed_ast10x0_sbc_info);
      type_register_static(&aspeed_sbc_info);
  }
 
#9 lore raw

PATCH v5 7/10 hw/misc/aspeed_sbc: Add CAMP2 support for OTP data reads

In reply to Kane Chen via

From: Kane-Chen-AS <[email protected]>

The OTP space contains three types of entries: data, conf, and strap. Data entries consist of two DWORDs, while the other types contain only one DWORD. This change adds the R_CAMP2 register (0x024 / 4) to store the second DWORD when reading from the OTP data region.

With this enhancement, OTP reads now correctly return both DWORDs for data entries via the CAMP registers, along with improved address validation and error handling.

---
 hw/misc/aspeed_sbc.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
hw/misc/aspeed_sbc.c +27 -0
index 052c70fd42..787e2d0489 100644
@@ -22,6 +22,7 @@
 #define R_ADDR          (0x010 / 4)
 #define R_STATUS        (0x014 / 4)
 #define R_CAMP1         (0x020 / 4)
+#define R_CAMP2         (0x024 / 4)
 #define R_QSR           (0x040 / 4)
 
 /* R_STATUS */
@@ -50,6 +51,8 @@
 #define SBC_OTP_CMD_READ 0x23b1e361
 #define SBC_OTP_CMD_PROG 0x23b1e364
 
+#define OTP_DATA_DWORD_COUNT        (0x800)
+#define OTP_TOTAL_DWORD_COUNT       (0x1000)
 static uint64_t aspeed_sbc_read(void *opaque, hwaddr addr, unsigned int size)
 {
     AspeedSBCState *s = ASPEED_SBC(opaque);
@@ -72,6 +75,16 @@ static bool aspeed_sbc_otp_read(AspeedSBCState *s,
     MemTxResult ret;
     AspeedOTPState *otp = &s->otp;
     uint32_t value, otp_offset;
+    bool is_data = false;
+
+    if (otp_addr < OTP_DATA_DWORD_COUNT) {
+        is_data = true;
+    } else if (otp_addr >= OTP_TOTAL_DWORD_COUNT) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "Invalid OTP addr 0x%x\n",
+                      otp_addr);
+        return false;
+    }
 
     otp_offset = otp_addr << 2;
     ret = address_space_read(&otp->as, otp_offset, MEMTXATTRS_UNSPECIFIED,
@@ -85,6 +98,20 @@ static bool aspeed_sbc_otp_read(AspeedSBCState *s,
     s->regs[R_CAMP1] = value;
     trace_aspeed_sbc_otp_read(otp_addr, value);
 
+    if (is_data) {
+        ret = address_space_read(&otp->as, otp_offset + 4,
+                                 MEMTXATTRS_UNSPECIFIED,
+                                 &value, sizeof(value));
+        if (ret != MEMTX_OK) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "Failed to read OTP memory, addr = %x\n",
+                          otp_addr);
+            return false;
+        }
+        s->regs[R_CAMP2] = value;
+        trace_aspeed_sbc_otp_read(otp_addr + 1, value);
+    }
+
     return true;
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v5 7/10
#10 lore raw

Re: [SPAM] [PATCH v5 07/10] hw/misc/aspeed_sbc: Add CAMP2 support for OTP data reads

Quoted 7 lines · Kane Chen

From: Kane-Chen-AS <[email protected]>

The OTP space contains three types of entries: data, conf, and strap. Data entries consist of two DWORDs, while the other types contain only one DWORD. This change adds the R_CAMP2 register (0x024 / 4) to store the second DWORD when reading from the OTP data region.

Quoted 5 lines

With this enhancement, OTP reads now correctly return both DWORDs for data entries via the CAMP registers, along with improved address validation and error handling.

Thanks,

C.

Quoted 63 lines
---
  hw/misc/aspeed_sbc.c | 27 +++++++++++++++++++++++++++
  1 file changed, 27 insertions(+)
hw/misc/aspeed_sbc.c +27 -0
index 052c70fd42..787e2d0489 100644
@@ -22,6 +22,7 @@
  #define R_ADDR          (0x010 / 4)
  #define R_STATUS        (0x014 / 4)
  #define R_CAMP1         (0x020 / 4)
+#define R_CAMP2         (0x024 / 4)
  #define R_QSR           (0x040 / 4)
 
  /* R_STATUS */
@@ -50,6 +51,8 @@
  #define SBC_OTP_CMD_READ 0x23b1e361
  #define SBC_OTP_CMD_PROG 0x23b1e364
 
+#define OTP_DATA_DWORD_COUNT        (0x800)
+#define OTP_TOTAL_DWORD_COUNT       (0x1000)
  static uint64_t aspeed_sbc_read(void *opaque, hwaddr addr, unsigned int size)
  {
      AspeedSBCState *s = ASPEED_SBC(opaque);
@@ -72,6 +75,16 @@ static bool aspeed_sbc_otp_read(AspeedSBCState *s,
      MemTxResult ret;
      AspeedOTPState *otp = &s->otp;
      uint32_t value, otp_offset;
+    bool is_data = false;
+
+    if (otp_addr < OTP_DATA_DWORD_COUNT) {
+        is_data = true;
+    } else if (otp_addr >= OTP_TOTAL_DWORD_COUNT) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "Invalid OTP addr 0x%x\n",
+                      otp_addr);
+        return false;
+    }
 
      otp_offset = otp_addr << 2;
      ret = address_space_read(&otp->as, otp_offset, MEMTXATTRS_UNSPECIFIED,
@@ -85,6 +98,20 @@ static bool aspeed_sbc_otp_read(AspeedSBCState *s,
      s->regs[R_CAMP1] = value;
      trace_aspeed_sbc_otp_read(otp_addr, value);
 
+    if (is_data) {
+        ret = address_space_read(&otp->as, otp_offset + 4,
+                                 MEMTXATTRS_UNSPECIFIED,
+                                 &value, sizeof(value));
+        if (ret != MEMTX_OK) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "Failed to read OTP memory, addr = %x\n",
+                          otp_addr);
+            return false;
+        }
+        s->regs[R_CAMP2] = value;
+        trace_aspeed_sbc_otp_read(otp_addr + 1, value);
+    }
+
      return true;
  }
 
#11 lore raw

PATCH v5 8/10 hw/misc/aspeed_sbc: Handle OTP write command for voltage mode registers

In reply to Kane Chen via

From: Kane-Chen-AS <[email protected]>

Extend OTP command handling to recognize specific voltage mode register addresses and emulate the expected hardware behavior. Without this change, legitimate voltage mode change requests would be incorrectly reported as "Unknown command" and logged as an error.

This implementation does not perform actual mode changes, but ensures that valid requests are accepted and ignored as per hardware behavior.

---
 hw/misc/aspeed_sbc.c | 41 +++++++++++++++++++++++++++++++++++++++++
 hw/misc/trace-events |  1 +
 2 files changed, 42 insertions(+)
hw/misc/aspeed_sbc.c +41 -0
index 787e2d0489..2fc5db749d 100644
@@ -49,10 +49,17 @@
 #define OTP_MEMORY_SIZE 0x4000
 /* OTP command */
 #define SBC_OTP_CMD_READ 0x23b1e361
+#define SBC_OTP_CMD_WRITE 0x23b1e362
 #define SBC_OTP_CMD_PROG 0x23b1e364
 
 #define OTP_DATA_DWORD_COUNT        (0x800)
 #define OTP_TOTAL_DWORD_COUNT       (0x1000)
+
+/* Voltage mode */
+#define MODE_REGISTER               (0x1000)
+#define MODE_REGISTER_A             (0x3000)
+#define MODE_REGISTER_B             (0x5000)
+
 static uint64_t aspeed_sbc_read(void *opaque, hwaddr addr, unsigned int size)
 {
     AspeedSBCState *s = ASPEED_SBC(opaque);
@@ -115,6 +122,37 @@ static bool aspeed_sbc_otp_read(AspeedSBCState *s,
     return true;
 }
 
+static bool mode_handler(uint32_t otp_addr)
+{
+    switch (otp_addr) {
+    case MODE_REGISTER:
+    case MODE_REGISTER_A:
+    case MODE_REGISTER_B:
+        /* HW behavior, do nothing here */
+        return true;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "Unsupported address 0x%x\n",
+                      otp_addr);
+        return false;
+    }
+}
+
+static bool aspeed_sbc_otp_write(AspeedSBCState *s,
+                                    uint32_t otp_addr)
+{
+    if (otp_addr == 0) {
+        trace_aspeed_sbc_ignore_cmd(otp_addr);
+        return true;
+    } else {
+        if (mode_handler(otp_addr) == false) {
+            return false;
+        }
+    }
+
+    return true;
+}
+
 static bool aspeed_sbc_otp_prog(AspeedSBCState *s,
                                    uint32_t otp_addr)
 {
@@ -157,6 +195,9 @@ static void aspeed_sbc_handle_command(void *opaque, uint32_t cmd)
     case SBC_OTP_CMD_READ:
         ret = aspeed_sbc_otp_read(s, otp_addr);
         break;
+    case SBC_OTP_CMD_WRITE:
+        ret = aspeed_sbc_otp_write(s, otp_addr);
+        break;
     case SBC_OTP_CMD_PROG:
         ret = aspeed_sbc_otp_prog(s, otp_addr);
         break;
hw/misc/trace-events +1 -0
index 9e05b82f37..eeb9243898 100644
@@ -91,6 +91,7 @@ slavio_led_mem_writew(uint32_t val) "Write diagnostic LED 0x%04x"
 slavio_led_mem_readw(uint32_t ret) "Read diagnostic LED 0x%04x"
 
 # aspeed_sbc.c
+aspeed_sbc_ignore_cmd(uint32_t cmd) "Ignoring command 0x%" PRIx32
 aspeed_sbc_handle_cmd(uint32_t cmd, uint32_t addr, bool ret) "Handling command 0x%" PRIx32 " for OTP addr 0x%" PRIx32 " Result: %d"
 aspeed_sbc_otp_read(uint32_t addr, uint32_t value) "OTP Memory read: addr 0x%" PRIx32 " value 0x%" PRIx32
 aspeed_sbc_otp_prog(uint32_t addr, uint32_t value) "OTP Memory write: addr 0x%" PRIx32 " value 0x%" PRIx32
Signature · 1 line
2.43.0
Reviewed-by on v5 8/10
#12 lore raw

Re: [SPAM] [PATCH v5 08/10] hw/misc/aspeed_sbc: Handle OTP write command for voltage mode registers

Quoted 11 lines · Kane Chen

From: Kane-Chen-AS <[email protected]>

Extend OTP command handling to recognize specific voltage mode register addresses and emulate the expected hardware behavior. Without this change, legitimate voltage mode change requests would be incorrectly reported as "Unknown command" and logged as an error.

This implementation does not perform actual mode changes, but ensures that valid requests are accepted and ignored as per hardware behavior.

Thanks,

C.

Quoted 87 lines
---
  hw/misc/aspeed_sbc.c | 41 +++++++++++++++++++++++++++++++++++++++++
  hw/misc/trace-events |  1 +
  2 files changed, 42 insertions(+)
hw/misc/aspeed_sbc.c +41 -0
index 787e2d0489..2fc5db749d 100644
@@ -49,10 +49,17 @@
  #define OTP_MEMORY_SIZE 0x4000
  /* OTP command */
  #define SBC_OTP_CMD_READ 0x23b1e361
+#define SBC_OTP_CMD_WRITE 0x23b1e362
  #define SBC_OTP_CMD_PROG 0x23b1e364
 
  #define OTP_DATA_DWORD_COUNT        (0x800)
  #define OTP_TOTAL_DWORD_COUNT       (0x1000)
+
+/* Voltage mode */
+#define MODE_REGISTER               (0x1000)
+#define MODE_REGISTER_A             (0x3000)
+#define MODE_REGISTER_B             (0x5000)
+
  static uint64_t aspeed_sbc_read(void *opaque, hwaddr addr, unsigned int size)
  {
      AspeedSBCState *s = ASPEED_SBC(opaque);
@@ -115,6 +122,37 @@ static bool aspeed_sbc_otp_read(AspeedSBCState *s,
      return true;
  }
 
+static bool mode_handler(uint32_t otp_addr)
+{
+    switch (otp_addr) {
+    case MODE_REGISTER:
+    case MODE_REGISTER_A:
+    case MODE_REGISTER_B:
+        /* HW behavior, do nothing here */
+        return true;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "Unsupported address 0x%x\n",
+                      otp_addr);
+        return false;
+    }
+}
+
+static bool aspeed_sbc_otp_write(AspeedSBCState *s,
+                                    uint32_t otp_addr)
+{
+    if (otp_addr == 0) {
+        trace_aspeed_sbc_ignore_cmd(otp_addr);
+        return true;
+    } else {
+        if (mode_handler(otp_addr) == false) {
+            return false;
+        }
+    }
+
+    return true;
+}
+
  static bool aspeed_sbc_otp_prog(AspeedSBCState *s,
                                     uint32_t otp_addr)
  {
@@ -157,6 +195,9 @@ static void aspeed_sbc_handle_command(void *opaque, uint32_t cmd)
      case SBC_OTP_CMD_READ:
          ret = aspeed_sbc_otp_read(s, otp_addr);
          break;
+    case SBC_OTP_CMD_WRITE:
+        ret = aspeed_sbc_otp_write(s, otp_addr);
+        break;
      case SBC_OTP_CMD_PROG:
          ret = aspeed_sbc_otp_prog(s, otp_addr);
          break;
hw/misc/trace-events +1 -0
index 9e05b82f37..eeb9243898 100644
@@ -91,6 +91,7 @@ slavio_led_mem_writew(uint32_t val) "Write diagnostic LED 0x%04x"
  slavio_led_mem_readw(uint32_t ret) "Read diagnostic LED 0x%04x"
 
  # aspeed_sbc.c
+aspeed_sbc_ignore_cmd(uint32_t cmd) "Ignoring command 0x%" PRIx32
  aspeed_sbc_handle_cmd(uint32_t cmd, uint32_t addr, bool ret) "Handling command 0x%" PRIx32 " for OTP addr 0x%" PRIx32 " Result: %d"
  aspeed_sbc_otp_read(uint32_t addr, uint32_t value) "OTP Memory read: addr 0x%" PRIx32 " value 0x%" PRIx32
  aspeed_sbc_otp_prog(uint32_t addr, uint32_t value) "OTP Memory write: addr 0x%" PRIx32 " value 0x%" PRIx32
#13 lore raw

PATCH v5 9/10 tests/function/aspeed: Add OTP functional test

In reply to Kane Chen via

From: Kane-Chen-AS <[email protected]>

On boot, the SoC firmware reads data from the OTP region to obtain the chip ID and default settings. This change adds test cases to verify that the firmware can boot correctly with a pre-configured OTP image.

---
 tests/functional/meson.build            |  2 +
 tests/functional/test_arm_aspeed_otp.py | 55 +++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 tests/functional/test_arm_aspeed_otp.py
tests/functional/meson.build +2 -0
index 311c6f1806..c731b779dd 100644
@@ -34,6 +34,7 @@ test_timeouts = {
   'arm_aspeed_bletchley' : 480,
   'arm_aspeed_catalina' : 480,
   'arm_aspeed_gb200nvl_bmc' : 480,
+  'arm_aspeed_otp': 1200,
   'arm_aspeed_rainier' : 480,
   'arm_bpim2u' : 500,
   'arm_collie' : 180,
@@ -132,6 +133,7 @@ tests_arm_system_thorough = [
   'arm_aspeed_bletchley',
   'arm_aspeed_catalina',
   'arm_aspeed_gb200nvl_bmc',
+  'arm_aspeed_otp',
   'arm_aspeed_rainier',
   'arm_bpim2u',
   'arm_canona1100',
tests/functional/test_arm_aspeed_otp.py new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
2.43.0
#14 lore raw

Re: [SPAM] [PATCH v5 09/10] tests/function/aspeed: Add OTP functional test

Hello Kane,

+ Thomas

tests/functional/test_arm_aspeed_otp.py

Quoted 34 lines · Kane Chen

From: Kane-Chen-AS <[email protected]>

On boot, the SoC firmware reads data from the OTP region to obtain the chip ID and default settings. This change adds test cases to verify that the firmware can boot correctly with a pre-configured OTP image.

---
  tests/functional/meson.build            |  2 +
  tests/functional/test_arm_aspeed_otp.py | 55 +++++++++++++++++++++++++
  2 files changed, 57 insertions(+)

create mode 100644 tests/functional/test_arm_aspeed_otp.py

tests/functional/meson.build +2 -0
index 311c6f1806..c731b779dd 100644
@@ -34,6 +34,7 @@ test_timeouts = {
    'arm_aspeed_bletchley' : 480,
    'arm_aspeed_catalina' : 480,
    'arm_aspeed_gb200nvl_bmc' : 480,
+  'arm_aspeed_otp': 1200,
    'arm_aspeed_rainier' : 480,
    'arm_bpim2u' : 500,
    'arm_collie' : 180,
@@ -132,6 +133,7 @@ tests_arm_system_thorough = [
    'arm_aspeed_bletchley',
    'arm_aspeed_catalina',
    'arm_aspeed_gb200nvl_bmc',
+  'arm_aspeed_otp',
    'arm_aspeed_rainier',
    'arm_bpim2u',
    'arm_canona1100',
tests/functional/test_arm_aspeed_otp.py +0 -0

The tests/functional directory was recently reorganized.

Also, I think I would prefer the new otp test to be part of the existing test files :

tests/functional/arm/test_aspeed_ast1030.py
tests/functional/arm/test_aspeed_ast2600.py

Something to discuss since test_aspeed_ast2600.py is rather big.

tests/functional/test_arm_aspeed_otp.py line 8

Quoted 13 lines

new file mode 100644
index 0000000000..48c7cad3f3

tests/functional/test_arm_aspeed_otp.py new file +8 -0
@@ -0,0 +1,55 @@
+import os
+import time
+import tempfile
+import subprocess
+
+from qemu_test import LinuxKernelTest, Asset> +from aspeed import AspeedTest
+from qemu_test import exec_command_and_wait_for_pattern, skipIfMissingCommands
+

Please add an extra blank line

tests/functional/test_arm_aspeed_otp.py line 14

Quoted 5 lines
tests/functional/test_arm_aspeed_otp.py new file +5 -0
+class AspeedOtpMemoryTest(AspeedTest):
+    # AST2600 SDK image
+    ASSET_SDK_V907_AST2600 = Asset(
+        'https://github.com/AspeedTech-BMC/openbmc/releases/download/v09.07/ast2600-default-obmc.tar.gz',
+        'cb6c08595bcbba1672ce716b068ba4e48eda1ed9abe78a07b30392ba2278feba')

Please update first all functional tests with the new SDK v9.07 images.

tests/functional/test_arm_aspeed_otp.py line 19

Quoted 5 lines
tests/functional/test_arm_aspeed_otp.py new file +5 -0
+
+    # AST1030 Zephyr image
+    ASSET_ZEPHYR_3_02 = Asset(
+        'https://github.com/AspeedTech-BMC/zephyr/releases/download/v00.03.02/ast1030-evb-demo.zip',
+        '1ec83caab3ddd5d09481772801be7210e222cb015ce22ec6fffb8a76956dcd4f')

Same for Zephyr images

tests/functional/test_arm_aspeed_otp.py line 31

Quoted 12 lines
tests/functional/test_arm_aspeed_otp.py new file +12 -0
+
+    def generate_otpmem_image(self):
+        path = self.scratch_file("otpmem.img")
+        pattern = b'\x00\x00\x00\x00\xff\xff\xff\xff' * (16 * 1024 // 8)
+        with open(path, "wb") as f:
+            f.write(pattern)
+        return path
+
+    def test_ast2600_otp_blockdev_device(self):
+        image_path = self.archive_extract(self.ASSET_SDK_V907_AST2600)
+        otp_img = self.generate_otpmem_image()
+        self.vm.set_machine("ast2600-evb")

Please move self.vm.set_machine() at the top of the routine.

Thanks,

C.

Quoted 24 lines
tests/functional/test_arm_aspeed_otp.py new file +24 -0
+        self.vm.set_console()
+        self.vm.add_args(
+            "-blockdev", f"driver=file,filename={otp_img},node-name=otp",
+            "-global", "aspeed-otp.drive=otp",
+        )
+        self.do_test_arm_aspeed_sdk_start(self.scratch_file("ast2600-default", "image-bmc"))
+        self.wait_for_console_pattern("ast2600-default login:")
+
+    def test_ast1030_otp_blockdev_device(self):
+        kernel_name = "ast1030-evb-demo-3/zephyr.elf"
+        kernel_file = self.archive_extract(self.ASSET_ZEPHYR_3_02, member=kernel_name)
+        otp_img = self.generate_otpmem_image()
+        self.vm.set_machine("ast1030-evb")
+        self.vm.set_console()
+        self.vm.add_args(
+            "-kernel", kernel_file,
+            "-blockdev", f"driver=file,filename={otp_img},node-name=otp",
+            "-global", "aspeed-otp.drive=otp",
+        )
+        self.vm.launch()
+        self.wait_for_console_pattern("Booting Zephyr OS")
+
+if __name__ == '__main__':
+    AspeedTest.main()
#15 lore raw

RE: [SPAM] [PATCH v5 09/10] tests/function/aspeed: Add OTP functional test

Hi Cédric,

Many thanks for reviewing. I will revise the test script as suggested and resubmit the patch.

Best regards,
Kane

Quoted 160 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Tuesday, September 2, 2025 1:41 PM
To: Kane Chen <[email protected]>; Peter Maydell <[email protected]>; Steven Lee <[email protected]>; Troy Lee <[email protected]>; Jamin Lin <[email protected]>; Andrew Jeffery <[email protected]>; Joel Stanley <[email protected]>; open list:ASPEED BMCs <[email protected]>; open list:All patches CC here <[email protected]>; Thomas Huth <[email protected]>
Cc: Troy Lee <[email protected]>
Subject: Re: [SPAM] [PATCH v5 09/10] tests/function/aspeed: Add OTP functional test

Hello Kane,

+ Thomas

Quoted 10 lines · Kane Chen

From: Kane-Chen-AS <[email protected]>

On boot, the SoC firmware reads data from the OTP region to obtain the chip ID and default settings. This change adds test cases to verify that the firmware can boot correctly with a pre-configured OTP image.

---
  tests/functional/meson.build            |  2 +
  tests/functional/test_arm_aspeed_otp.py | 55

+++++++++++++++++++++++++

tests/functional/test_arm_aspeed_otp.py

Quoted 25 lines
  2 files changed, 57 insertions(+)

create mode 100644 tests/functional/test_arm_aspeed_otp.py

(quoted diff) +0 -0

b/tests/functional/meson.build index 311c6f1806..c731b779dd 100644

tests/functional/meson.build +2 -0
@@ -34,6 +34,7 @@ test_timeouts = {
    'arm_aspeed_bletchley' : 480,
    'arm_aspeed_catalina' : 480,
    'arm_aspeed_gb200nvl_bmc' : 480,
+  'arm_aspeed_otp': 1200,
    'arm_aspeed_rainier' : 480,
    'arm_bpim2u' : 500,
    'arm_collie' : 180,
@@ -132,6 +133,7 @@ tests_arm_system_thorough = [
    'arm_aspeed_bletchley',
    'arm_aspeed_catalina',
    'arm_aspeed_gb200nvl_bmc',
+  'arm_aspeed_otp',
    'arm_aspeed_rainier',
    'arm_bpim2u',
    'arm_canona1100',
tests/functional/test_arm_aspeed_otp.py +0 -0

The tests/functional directory was recently reorganized.

Also, I think I would prefer the new otp test to be part of the existing test files :

tests/functional/arm/test_aspeed_ast1030.py
tests/functional/arm/test_aspeed_ast2600.py

Something to discuss since test_aspeed_ast2600.py is rather big.

Quoted 5 lines

new file mode 100644
index 0000000000..48c7cad3f3

tests/functional/test_arm_aspeed_otp.py line 9

Quoted 9 lines
tests/functional/test_arm_aspeed_otp.py new file +9 -0
@@ -0,0 +1,55 @@
+import os
+import time
+import tempfile
+import subprocess
+
+from qemu_test import LinuxKernelTest, Asset> +from aspeed import
+AspeedTest from qemu_test import exec_command_and_wait_for_pattern,
+skipIfMissingCommands
+

Please add an extra blank line

tests/functional/test_arm_aspeed_otp.py line 15

Quoted 4 lines
tests/functional/test_arm_aspeed_otp.py new file +4 -0
+class AspeedOtpMemoryTest(AspeedTest):
+    # AST2600 SDK image
+    ASSET_SDK_V907_AST2600 = Asset(
+

'https://github.com/AspeedTech-BMC/openbmc/releases/download/v09.07/a st2600-default-obmc.tar.gz',

tests/functional/test_arm_aspeed_otp.py line 14

Quoted 2 lines
tests/functional/test_arm_aspeed_otp.py new file +1 -0
+

+'cb6c08595bcbba1672ce716b068ba4e48eda1ed9abe78a07b30392ba2278fe ba')

Please update first all functional tests with the new SDK v9.07 images.

tests/functional/test_arm_aspeed_otp.py line 20

Quoted 4 lines
tests/functional/test_arm_aspeed_otp.py new file +4 -0
+
+    # AST1030 Zephyr image
+    ASSET_ZEPHYR_3_02 = Asset(
+

'https://github.com/AspeedTech-BMC/zephyr/releases/download/v00.03.02/ ast1030-evb-demo.zip',

tests/functional/test_arm_aspeed_otp.py line 20

Quoted 2 lines
tests/functional/test_arm_aspeed_otp.py new file +2 -0
+
+

'1ec83caab3ddd5d09481772801be7210e222cb015ce22ec6fffb8a76956dcd4f' )

Same for Zephyr images

tests/functional/test_arm_aspeed_otp.py

Quoted 10 lines
tests/functional/test_arm_aspeed_otp.py new file +10 -0
+
+    def generate_otpmem_image(self):
+        path = self.scratch_file("otpmem.img")
+        pattern = b'\x00\x00\x00\x00\xff\xff\xff\xff' * (16 * 1024 // 8)
+        with open(path, "wb") as f:
+            f.write(pattern)
+        return path
+
+    def test_ast2600_otp_blockdev_device(self):
+        image_path =

self.archive_extract(self.ASSET_SDK_V907_AST2600)

tests/functional/test_arm_aspeed_otp.py line 31

Quoted 2 lines
tests/functional/test_arm_aspeed_otp.py new file +2 -0
+        otp_img = self.generate_otpmem_image()
+        self.vm.set_machine("ast2600-evb")

Please move self.vm.set_machine() at the top of the routine.

Thanks,

C.

tests/functional/test_arm_aspeed_otp.py

Quoted 3 lines
tests/functional/test_arm_aspeed_otp.py new file +3 -0
+        self.vm.set_console()
+        self.vm.add_args(
+            "-blockdev",

f"driver=file,filename={otp_img},node-name=otp",

tests/functional/test_arm_aspeed_otp.py line 39

Quoted 3 lines
tests/functional/test_arm_aspeed_otp.py new file +3 -0
+            "-global", "aspeed-otp.drive=otp",
+        )
+

self.do_test_arm_aspeed_sdk_start(self.scratch_file("ast2600-default", "image-bmc"))

tests/functional/test_arm_aspeed_otp.py

Quoted 5 lines
tests/functional/test_arm_aspeed_otp.py new file +5 -0
+        self.wait_for_console_pattern("ast2600-default login:")
+
+    def test_ast1030_otp_blockdev_device(self):
+        kernel_name = "ast1030-evb-demo-3/zephyr.elf"
+        kernel_file = self.archive_extract(self.ASSET_ZEPHYR_3_02,

member=kernel_name)

tests/functional/test_arm_aspeed_otp.py

Quoted 6 lines
tests/functional/test_arm_aspeed_otp.py new file +6 -0
+        otp_img = self.generate_otpmem_image()
+        self.vm.set_machine("ast1030-evb")
+        self.vm.set_console()
+        self.vm.add_args(
+            "-kernel", kernel_file,
+            "-blockdev",

f"driver=file,filename={otp_img},node-name=otp",

Quoted 7 lines
tests/functional/test_arm_aspeed_otp.py new file +7 -0
+            "-global", "aspeed-otp.drive=otp",
+        )
+        self.vm.launch()
+        self.wait_for_console_pattern("Booting Zephyr OS")
+
+if __name__ == '__main__':
+    AspeedTest.main()
#16 lore raw

PATCH v5 10/10 docs/system/arm/aspeed: Document OTP memory options

In reply to Kane Chen via

From: Kane-Chen-AS <[email protected]>

Add documentation for the OTP memory module used by AST2600 and AST1030 SoCs, and describe options for using a pre-generated image or an internal buffer. Include example commands for configuration and image generation.

---
 docs/system/arm/aspeed.rst | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
docs/system/arm/aspeed.rst +31 -0
index bf18c56347..6317c0e910 100644
@@ -243,6 +243,37 @@ under Linux), use :
 
   -M ast2500-evb,bmc-console=uart3
 
+OTP Option
+^^^^^^^^^^
+
+Both the AST2600 and AST1030 chips use the same One Time Programmable
+(OTP) memory module, which is utilized for configuration, key storage,
+and storing user-programmable data. This OTP memory module is managed
+by the Secure Boot Controller (SBC). The following options can be
+specified or omitted based on your needs.
+
+  * When the options are specified, the pre-generated configuration
+    file will be used as the OTP memory storage.
+
+  * When the options are omitted, an internal memory buffer will be
+    used to store the OTP memory data.
+
+.. code-block:: bash
+
+  -blockdev driver=file,filename=otpmem.img,node-name=otp \
+  -global aspeed-otp.drive=otp \
+
+The following bash command can be used to generate a default
+configuration file for OTP memory:
+
+.. code-block:: bash
+
+  if [ ! -f otpmem.img ]; then
+    for i in $(seq 1 2048); do
+      printf '\x00\x00\x00\x00\xff\xff\xff\xff'
+    done > otpmem.img
+  fi
+
 Aspeed 2700 family boards (``ast2700-evb``)
 ==================================================================
 
Signature · 1 line
2.43.0
Reviewed-by on v5 10/10
#17 lore raw

Re: [SPAM] [PATCH v5 10/10] docs/system/arm/aspeed: Document OTP memory options

Quoted 44 lines · Kane Chen

From: Kane-Chen-AS <[email protected]>

Add documentation for the OTP memory module used by AST2600 and AST1030 SoCs, and describe options for using a pre-generated image or an internal buffer. Include example commands for configuration and image generation.

---
  docs/system/arm/aspeed.rst | 31 +++++++++++++++++++++++++++++++
  1 file changed, 31 insertions(+)
docs/system/arm/aspeed.rst +24 -0
index bf18c56347..6317c0e910 100644
@@ -243,6 +243,37 @@ under Linux), use :
 
    -M ast2500-evb,bmc-console=uart3
 
+OTP Option
+^^^^^^^^^^
+
+Both the AST2600 and AST1030 chips use the same One Time Programmable
+(OTP) memory module, which is utilized for configuration, key storage,
+and storing user-programmable data. This OTP memory module is managed
+by the Secure Boot Controller (SBC). The following options can be
+specified or omitted based on your needs.
+
+  * When the options are specified, the pre-generated configuration
+    file will be used as the OTP memory storage.
+
+  * When the options are omitted, an internal memory buffer will be
+    used to store the OTP memory data.
+
+.. code-block:: bash
+
+  -blockdev driver=file,filename=otpmem.img,node-name=otp \
+  -global aspeed-otp.drive=otp \
+
+The following bash command can be used to generate a default
+configuration file for OTP memory:
+
+.. code-block:: bash

docs/system/arm/aspeed.rst under Linux), use : · line 279

Quoted 10 lines
docs/system/arm/aspeed.rst +7 -0
+
+  if [ ! -f otpmem.img ]; then
+    for i in $(seq 1 2048); do
+      printf '\x00\x00\x00\x00\xff\xff\xff\xff'
+    done > otpmem.img
+  fi
+
  Aspeed 2700 family boards (``ast2700-evb``)
  ==================================================================
 

Thanks,

C.

#18 lore raw
In reply to Kane Chen via

Hello Kane,

Quoted 82 lines · Kane Chen

From: Kane-Chen-AS <[email protected]>

This patch series extends the QEMU model for the ASPEED OTP (One-Time Programmable) memory device with block backend support and tighter integration with the SoC and machine configuration.

The OTP model simulates a simple fuse array used in ASPEED SoCs for secure boot, configuration, key storage, and user-programmable data. The updated model adds support for loading initial OTP content from a file via the QEMU CLI.

Example usage:

   ./qemu-system-arm \
     -machine ast2600-evb \
     -blockdev driver=file,filename=otpmem.img,node-name=otp \
     -global aspeed-otp.drive=otp \
     ...

Any feedback or suggestions are appreciated!

Kane
---

ChangeLog
---------
v5:
- Add OTP programming semantics and tracing
- Integrate OTP into AST1030 SoC
- Add CAMP2 register support for reading both DWORDs of OTP data entries
- Handle voltage mode write commands to avoid misreporting valid requests as "Unknown command"
- Add functional test to verify firmware boot with a pre-configured OTP image
- Add documentation for OTP memory options in QEMU

v4:
- Add a 'drive' property to allow backing OTP data with a block device
- Expose a machine parameter (-machine otpmem=XXX) for convenient aliasing of the OTP drive via QOM path

v3:
- Switched to object_property_set_int() for setting "size"
- Simplified qdev_realize() error handling by passing errp directly
- Added "drive" property to OTP model for future extensibility

v2:
- Rename device from 'aspeed_otpmem' to 'aspeed_otp' and move it to hw/nvram/
- Move OTP device realization from instance_init to the realize function
- Improve error logging with qemu_log_mask() and remove unused error propagation

v1:
- Initial version

---

Kane-Chen-AS (10):
hw/nvram/aspeed_otp: Add ASPEED OTP memory device model hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC hw/arm: Integrate ASPEED OTP memory support into AST2600 SoCs hw/nvram/aspeed_otp: Add 'drive' property to support block backend hw/nvram/aspeed_otp: Add OTP programming semantics and tracing hw/arm: Integrate ASPEED OTP memory support into AST1030 SoCs hw/misc/aspeed_sbc: Add CAMP2 support for OTP data reads hw/misc/aspeed_sbc: Handle OTP write command for voltage mode
registers
tests/function/aspeed: Add OTP functional test docs/system/arm/aspeed: Document OTP memory options

  docs/system/arm/aspeed.rst              |  31 ++++
  include/hw/misc/aspeed_sbc.h            |   6 +
  include/hw/nvram/aspeed_otp.h           |  33 ++++
  hw/arm/aspeed_ast10x0.c                 |   2 +-
  hw/arm/aspeed_ast2600.c                 |   2 +-
  hw/misc/aspeed_sbc.c                    | 196 ++++++++++++++++++++++++
  hw/nvram/aspeed_otp.c                   | 190 +++++++++++++++++++++++
  hw/misc/trace-events                    |   6 +
  hw/nvram/meson.build                    |   4 +
  hw/nvram/trace-events                   |   5 +
  tests/functional/meson.build            |   2 +
  tests/functional/test_arm_aspeed_otp.py |  55 +++++++
  12 files changed, 530 insertions(+), 2 deletions(-)
Quoted 4 lines

create mode 100644 include/hw/nvram/aspeed_otp.h create mode 100644 hw/nvram/aspeed_otp.c
create mode 100644 tests/functional/test_arm_aspeed_otp.py

I will queue patches 1-8,10 in aspeed-next. No need to resend.

Please address the comments on patch 9 in a new series, Cc: Thomas.

Thanks,

C.

#19 lore raw

Hi Cédric,

Thank you for your help and the review. I’ll start a new thread to discuss the test script.

Best Regards,
Kane

Quoted 120 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Tuesday, September 2, 2025 1:44 PM
To: Kane Chen <[email protected]>; Peter Maydell <[email protected]>; Steven Lee <[email protected]>; Troy Lee <[email protected]>; Jamin Lin <[email protected]>; Andrew Jeffery <[email protected]>; Joel Stanley <[email protected]>; open list:ASPEED BMCs <[email protected]>; open list:All patches CC here <[email protected]>
Cc: Troy Lee <[email protected]>
Subject: Re: [SPAM] [PATCH v5 00/10] aspeed: OTP model, SBC integration, tests, and docs

Hello Kane,

Quoted 72 lines · Kane Chen

From: Kane-Chen-AS <[email protected]>

This patch series extends the QEMU model for the ASPEED OTP (One-Time Programmable) memory device with block backend support and tighter integration with the SoC and machine configuration.

The OTP model simulates a simple fuse array used in ASPEED SoCs for secure boot, configuration, key storage, and user-programmable data. The updated model adds support for loading initial OTP content from a file via the QEMU CLI.

Example usage:

   ./qemu-system-arm \
     -machine ast2600-evb \
     -blockdev driver=file,filename=otpmem.img,node-name=otp \
     -global aspeed-otp.drive=otp \
     ...

Any feedback or suggestions are appreciated!

Kane
---

ChangeLog
---------
v5:
- Add OTP programming semantics and tracing
- Integrate OTP into AST1030 SoC
- Add CAMP2 register support for reading both DWORDs of OTP data entries
- Handle voltage mode write commands to avoid misreporting valid requests as "Unknown command"
- Add functional test to verify firmware boot with a pre-configured OTP image
- Add documentation for OTP memory options in QEMU

v4:
- Add a 'drive' property to allow backing OTP data with a block device
- Expose a machine parameter (-machine otpmem=XXX) for convenient aliasing of the OTP drive via QOM path

v3:
- Switched to object_property_set_int() for setting "size"
- Simplified qdev_realize() error handling by passing errp directly
- Added "drive" property to OTP model for future extensibility

v2:
- Rename device from 'aspeed_otpmem' to 'aspeed_otp' and move it to hw/nvram/
- Move OTP device realization from instance_init to the realize function
- Improve error logging with qemu_log_mask() and remove unused error propagation

v1:
- Initial version

---

Kane-Chen-AS (10):
hw/nvram/aspeed_otp: Add ASPEED OTP memory device model hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC hw/arm: Integrate ASPEED OTP memory support into AST2600 SoCs hw/nvram/aspeed_otp: Add 'drive' property to support block backend hw/nvram/aspeed_otp: Add OTP programming semantics and tracing hw/arm: Integrate ASPEED OTP memory support into AST1030 SoCs hw/misc/aspeed_sbc: Add CAMP2 support for OTP data reads hw/misc/aspeed_sbc: Handle OTP write command for voltage mode
registers
tests/function/aspeed: Add OTP functional test docs/system/arm/aspeed: Document OTP memory options

Quoted 6 lines
  docs/system/arm/aspeed.rst              |  31 ++++
  include/hw/misc/aspeed_sbc.h            |   6 +
  include/hw/nvram/aspeed_otp.h           |  33 ++++
  hw/arm/aspeed_ast10x0.c                 |   2 +-
  hw/arm/aspeed_ast2600.c                 |   2 +-
  hw/misc/aspeed_sbc.c                    | 196

++++++++++++++++++++++++

Quoted 1 line
  hw/nvram/aspeed_otp.c                   | 190

+++++++++++++++++++++++

Quoted 10 lines
  hw/misc/trace-events                    |   6 +
  hw/nvram/meson.build                    |   4 +
  hw/nvram/trace-events                   |   5 +
  tests/functional/meson.build            |   2 +
  tests/functional/test_arm_aspeed_otp.py |  55 +++++++
  12 files changed, 530 insertions(+), 2 deletions(-)

create mode 100644 include/hw/nvram/aspeed_otp.h create mode 100644 hw/nvram/aspeed_otp.c
create mode 100644 tests/functional/test_arm_aspeed_otp.py

I will queue patches 1-8,10 in aspeed-next. No need to resend.

Please address the comments on patch 9 in a new series, Cc: Thomas.

Thanks,

C.