Skip to content

Commit 39b6772

Browse files
author
Jon Flatley
committed
[opentitantool] Add alert_handler magic value generation
Adds a new command, `opentitantool otp alert-crc`, for generating the magic value used to validate alert_handler register values during shutdown_init in ROM. Signed-off-by: Jon Flatley <[email protected]>
1 parent 0d3e153 commit 39b6772

File tree

8 files changed

+396
-42
lines changed

8 files changed

+396
-42
lines changed

sw/host/opentitanlib/src/otp/alert_handler.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,18 @@ impl AlertRegs {
156156
LcStateVal::Test => return Ok(alert),
157157
};
158158

159-
let class_enable = otp.read32("ROM_ALERT_CLASS_EN")?;
160-
let class_escalate = otp.read32("ROM_ALERT_ESCALATION")?;
159+
let class_enable = otp.read32("OWNER_SW_CFG_ROM_ALERT_CLASS_EN")?;
160+
let class_escalate = otp.read32("OWNER_SW_CFG_ROM_ALERT_ESCALATION")?;
161161

162162
for i in 0..ALERT_HANDLER_ALERT_CLASS_SHADOWED_MULTIREG_COUNT as usize {
163-
let value = otp.read32_offset(Some("ROM_ALERT_CLASSIFICATION"), i * 4)?;
163+
let value = otp.read32_offset("OWNER_SW_CFG_ROM_ALERT_CLASSIFICATION", i * 4)?;
164164
let cls = AlertClass::try_from(value.to_le_bytes()[lc_shift])?;
165165
let enable = AlertEnable::try_from(class_enable.to_le_bytes()[cls.index()])?;
166166
alert.configure(i, cls, enable)?;
167167
}
168168

169169
for i in 0..ALERT_HANDLER_LOC_ALERT_CLASS_SHADOWED_MULTIREG_COUNT as usize {
170-
let value = otp.read32_offset(Some("ROM_LOCAL_ALERT_CLASSIFICATION"), i * 4)?;
170+
let value = otp.read32_offset("OWNER_SW_CFG_ROM_LOCAL_ALERT_CLASSIFICATION", i * 4)?;
171171
let cls = AlertClass::try_from(value.to_le_bytes()[lc_shift])?;
172172
let enable = AlertEnable::try_from(class_enable.to_le_bytes()[cls.index()])?;
173173
alert.local_configure(i, cls, enable)?;
@@ -177,15 +177,15 @@ impl AlertRegs {
177177
let mut phase_cycs = [0; ALERT_HANDLER_PARAM_N_PHASES as usize];
178178
for phase in 0..ALERT_HANDLER_PARAM_N_PHASES as usize {
179179
phase_cycs[phase] = otp.read32_offset(
180-
Some("ROM_ALERT_PHASE_CYCLES"),
180+
"OWNER_SW_CFG_ROM_ALERT_PHASE_CYCLES",
181181
(i * phase_cycs.len() + phase) * 4,
182182
)?;
183183
}
184184
let config = AlertClassConfig {
185185
enabled: AlertEnable::try_from(class_enable.to_le_bytes()[i])?,
186186
escalate: AlertEscalate::try_from(class_escalate.to_le_bytes()[i])?,
187-
accum_thresh: otp.read32_offset(Some("ROM_ALERT_ACCUM_THRESH"), i * 4)?,
188-
timeout_cyc: otp.read32_offset(Some("ROM_ALERT_TIMEOUT_CYCLES"), i * 4)?,
187+
accum_thresh: otp.read32_offset("OWNER_SW_CFG_ROM_ALERT_ACCUM_THRESH", i * 4)?,
188+
timeout_cyc: otp.read32_offset("OWNER_SW_CFG_ROM_ALERT_TIMEOUT_CYCLES", i * 4)?,
189189
phase_cycs,
190190
};
191191
alert.class_configure(AlertClass::from_index(i), &config)?;
@@ -443,19 +443,21 @@ mod test {
443443

444444
// OTP values that corrispond to the above `TEST_REG` values.
445445
impl OtpRead for TestOtp {
446-
fn read32_offset(&self, name: Option<&str>, offset: usize) -> Result<u32> {
447-
let name = name.unwrap();
446+
fn read32_offset(&self, name: &str, offset: usize) -> Result<u32> {
448447
Ok(match name {
449-
"ROM_ALERT_CLASS_EN" => 0xa9a9a9a9,
450-
"ROM_ALERT_ESCALATION" => 0xd1d1d1d1,
451-
"ROM_ALERT_CLASSIFICATION" | "ROM_LOCAL_ALERT_CLASSIFICATION" => 0x94949494,
452-
"ROM_ALERT_PHASE_CYCLES" => [
448+
"OWNER_SW_CFG_ROM_ALERT_CLASS_EN" => 0xa9a9a9a9,
449+
"OWNER_SW_CFG_ROM_ALERT_ESCALATION" => 0xd1d1d1d1,
450+
"OWNER_SW_CFG_ROM_ALERT_CLASSIFICATION"
451+
| "OWNER_SW_CFG_ROM_LOCAL_ALERT_CLASSIFICATION" => 0x94949494,
452+
"OWNER_SW_CFG_ROM_ALERT_PHASE_CYCLES" => [
453453
0x00000000, 0x0000000a, 0x0000000a, 0xffffffff, // Class 0
454454
0x00000000, 0x0000000a, 0x0000000a, 0xffffffff, // Class 1
455455
0x00000000, 0x00000000, 0x00000000, 0x00000000, // Class 2
456456
0x00000000, 0x00000000, 0x00000000, 0x00000000, // Class 3
457457
][offset / 4],
458-
"ROM_ALERT_ACCUM_THRESH" | "ROM_ALERT_TIMEOUT_CYCLES" => 0x00000000,
458+
"OWNER_SW_CFG_ROM_ALERT_ACCUM_THRESH" | "OWNER_SW_CFG_ROM_ALERT_TIMEOUT_CYCLES" => {
459+
0x00000000
460+
}
459461
_ => panic!("No such OTP value {}", name),
460462
})
461463
}

sw/host/opentitanlib/src/otp/lc_state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct LcState {
2525
}
2626

2727
#[repr(u32)]
28+
#[derive(Copy, Clone)]
2829
pub enum LcStateVal {
2930
Test = 0xb2865fbb,
3031
Dev = 0x0b5a75e0,

sw/host/opentitanlib/src/otp/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ pub mod lc_state;
88
// TODO(lowRISC/opentitan#15443): Fix this lint.
99
#[allow(clippy::module_inception)]
1010
pub mod otp_img;
11-

0 commit comments

Comments
 (0)