Skip to content

Commit d7b4ee4

Browse files
committed
[ot] hw/opentitan: ot_otp: retrieve HW config parameters from buffered data
Signed-off-by: Emmanuel Blot <[email protected]>
1 parent d7583e8 commit d7b4ee4

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

hw/opentitan/ot_otp_dj.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,22 +1118,31 @@ ot_otp_dj_update_status_error(OtOTPImplIf *dev, OtOTPStatus error, bool set)
11181118

11191119
static void ot_otp_dj_pwr_load_hw_cfg(OtOTPEngineState *s)
11201120
{
1121-
OtOTPStorage *otp = s->otp;
1121+
OtOTPImplIfClass *ic = OT_OTP_IMPL_IF_GET_CLASS(s);
1122+
1123+
const OtOTPPartDesc *pdesc0 = &ic->part_descs[OTP_PART_HW_CFG0];
1124+
const OtOTPPartDesc *pdesc1 = &ic->part_descs[OTP_PART_HW_CFG1];
1125+
const OtOTPPartController *pctrl0 = &s->part_ctrls[OTP_PART_HW_CFG0];
1126+
const OtOTPPartController *pctrl1 = &s->part_ctrls[OTP_PART_HW_CFG1];
1127+
const uint8_t *pdata0 = (const uint8_t *)pctrl0->buffer.data;
1128+
const uint8_t *pdata1 = (const uint8_t *)pctrl1->buffer.data;
1129+
11221130
OtOTPHWCfg *hw_cfg = s->hw_cfg;
11231131

1124-
memcpy(hw_cfg->device_id, &otp->data[R_HW_CFG0_DEVICE_ID],
1132+
memcpy(hw_cfg->device_id, &pdata0[A_HW_CFG0_DEVICE_ID - pdesc0->offset],
11251133
sizeof(hw_cfg->device_id));
1126-
memcpy(hw_cfg->manuf_state, &otp->data[R_HW_CFG0_MANUF_STATE],
1134+
memcpy(hw_cfg->manuf_state, &pdata0[A_HW_CFG0_MANUF_STATE - pdesc0->offset],
11271135
sizeof(hw_cfg->manuf_state));
1128-
memcpy(hw_cfg->soc_dbg_state, &otp->data[R_HW_CFG1_SOC_DBG_STATE],
1136+
memcpy(hw_cfg->soc_dbg_state,
1137+
&pdata1[A_HW_CFG1_SOC_DBG_STATE - pdesc1->offset],
11291138
sizeof(hw_cfg->soc_dbg_state));
11301139
/* do not prevent execution from SRAM if no OTP configuration is loaded */
11311140
hw_cfg->en_sram_ifetch_mb8 =
1132-
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_SRAM_IFETCH] :
1141+
s->blk ? pdata1[A_HW_CFG1_EN_SRAM_IFETCH - pdesc1->offset] :
11331142
OT_MULTIBITBOOL8_TRUE;
11341143
/* do not prevent CSRNG app reads if no OTP configuration is loaded */
11351144
hw_cfg->en_csrng_sw_app_read_mb8 =
1136-
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_CSRNG_SW_APP_READ] :
1145+
s->blk ? pdata1[A_HW_CFG1_EN_CSRNG_SW_APP_READ - pdesc1->offset] :
11371146
OT_MULTIBITBOOL8_TRUE;
11381147
}
11391148

hw/opentitan/ot_otp_eg.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,20 +1007,28 @@ ot_otp_eg_update_status_error(OtOTPImplIf *dev, OtOTPStatus error, bool set)
10071007

10081008
static void ot_otp_eg_pwr_load_hw_cfg(OtOTPEngineState *s)
10091009
{
1010-
OtOTPStorage *otp = s->otp;
1010+
OtOTPImplIfClass *ic = OT_OTP_IMPL_IF_GET_CLASS(s);
1011+
1012+
const OtOTPPartDesc *pdesc0 = &ic->part_descs[OTP_PART_HW_CFG0];
1013+
const OtOTPPartDesc *pdesc1 = &ic->part_descs[OTP_PART_HW_CFG1];
1014+
const OtOTPPartController *pctrl0 = &s->part_ctrls[OTP_PART_HW_CFG0];
1015+
const OtOTPPartController *pctrl1 = &s->part_ctrls[OTP_PART_HW_CFG1];
1016+
const uint8_t *pdata0 = (const uint8_t *)pctrl0->buffer.data;
1017+
const uint8_t *pdata1 = (const uint8_t *)pctrl1->buffer.data;
1018+
10111019
OtOTPHWCfg *hw_cfg = s->hw_cfg;
10121020

1013-
memcpy(hw_cfg->device_id, &otp->data[R_HW_CFG0_DEVICE_ID],
1021+
memcpy(hw_cfg->device_id, &pdata0[A_HW_CFG0_DEVICE_ID - pdesc0->offset],
10141022
sizeof(hw_cfg->device_id));
1015-
memcpy(hw_cfg->manuf_state, &otp->data[R_HW_CFG0_MANUF_STATE],
1023+
memcpy(hw_cfg->manuf_state, &pdata0[A_HW_CFG0_MANUF_STATE - pdesc0->offset],
10161024
sizeof(hw_cfg->manuf_state));
10171025
/* do not prevent execution from SRAM if no OTP configuration is loaded */
10181026
hw_cfg->en_sram_ifetch_mb8 =
1019-
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_SRAM_IFETCH] :
1027+
s->blk ? pdata1[A_HW_CFG1_EN_SRAM_IFETCH - pdesc1->offset] :
10201028
OT_MULTIBITBOOL8_TRUE;
10211029
/* do not prevent CSRNG app reads if no OTP configuration is loaded */
10221030
hw_cfg->en_csrng_sw_app_read_mb8 =
1023-
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_CSRNG_SW_APP_READ] :
1031+
s->blk ? pdata1[A_HW_CFG1_EN_CSRNG_SW_APP_READ - pdesc1->offset] :
10241032
OT_MULTIBITBOOL8_TRUE;
10251033
}
10261034

0 commit comments

Comments
 (0)