Skip to content

Commit

Permalink
hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset
Browse files Browse the repository at this point in the history
Once a "One Time Programmable" is programmed, it shouldn't be reset.

Do not re-initialize the OTP content in the DeviceReset handler,
initialize it once in the DeviceRealize one.

Fixes: 9fb45c6 ("riscv: sifive: Implement a model for SiFive FU540 OTP")
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20211119104757.331579-1-f4bug@amsat.org>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
  • Loading branch information
philmd authored and alistair23 committed Nov 22, 2021
1 parent 6b717a8 commit 526e744
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions hw/misc/sifive_u_otp.c
Expand Up @@ -242,14 +242,10 @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)

if (blk_pread(s->blk, 0, s->fuse, filesize) != filesize) {
error_setg(errp, "failed to read the initial flash content");
return;
}
}
}
}

static void sifive_u_otp_reset(DeviceState *dev)
{
SiFiveUOTPState *s = SIFIVE_U_OTP(dev);

/* Initialize all fuses' initial value to 0xFFs */
memset(s->fuse, 0xff, sizeof(s->fuse));
Expand All @@ -266,13 +262,15 @@ static void sifive_u_otp_reset(DeviceState *dev)
serial_data = s->serial;
if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
&serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
error_report("write error index<%d>", index);
error_setg(errp, "failed to write index<%d>", index);
return;
}

serial_data = ~(s->serial);
if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
&serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
error_report("write error index<%d>", index + 1);
error_setg(errp, "failed to write index<%d>", index + 1);
return;
}
}

Expand All @@ -286,7 +284,6 @@ static void sifive_u_otp_class_init(ObjectClass *klass, void *data)

device_class_set_props(dc, sifive_u_otp_properties);
dc->realize = sifive_u_otp_realize;
dc->reset = sifive_u_otp_reset;
}

static const TypeInfo sifive_u_otp_info = {
Expand Down

0 comments on commit 526e744

Please sign in to comment.