Skip to content

Commit

Permalink
[ottool] Support chips with volatile RAW unlock disabled
Browse files Browse the repository at this point in the history
This updates the manuf_cp_volatile_unlock_raw test so that
we can indicate whether we expect the target to support volatile RAW
unlock or not.

Signed-off-by: Michael Schaffner <[email protected]>
  • Loading branch information
msfschaffner committed Feb 15, 2024
1 parent 9c78061 commit db8f9b8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
36 changes: 28 additions & 8 deletions sw/host/opentitanlib/src/test_utils/lc_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum LcTransitionError {
FailedToClaimMutex,
#[error("Volatile raw unlock is not supported on this chip.")]
VolatileRawUnlockNotSupported,
#[error("Volatile raw unlock is unexpectedly supported on this chip.")]
VolatileRawUnlockSupported,
#[error("LC transition target programming failed (target state: 0x{0:x}).")]
TargetProgrammingFailed(u32),
#[error("LC transition failed (status: 0x{0:x}).")]
Expand Down Expand Up @@ -216,6 +218,12 @@ pub fn trigger_lc_transition(
/// provided (a pre-requisite of the volatile operation. The device will NOT be reset into the
/// new lifecycle state as TAP straps are sampled again on a successfull transition. However,
/// the TAP can be switched from LC to RISCV on a successfull transition.
///
/// If the feature is not present in HW we expect the transition to fail with
/// a token error since the token is invalid for a real RAW unlock
/// transition. Use the expect_raw_unlock_supported argument to indicate
/// whether we expect this transition to succeed or not.
#[allow(clippy::too_many_arguments)]
pub fn trigger_volatile_raw_unlock<'t>(
transport: &'t TransportWrapper,
mut jtag: Box<dyn Jtag + 't>,
Expand All @@ -224,6 +232,7 @@ pub fn trigger_volatile_raw_unlock<'t>(
use_external_clk: bool,
post_transition_tap: JtagTap,
jtag_params: &JtagParams,
expect_raw_unlock_supported: bool,
) -> Result<Box<dyn Jtag + 't>> {
// Wait for the lc_ctrl to become initialized, claim the mutex, and program the target state
// and token CSRs.
Expand All @@ -237,8 +246,11 @@ pub fn trigger_volatile_raw_unlock<'t>(
jtag.write_lc_ctrl_reg(&LcCtrlReg::TransitionCtrl, ctrl.bits())?;

// Read back the volatile raw unlock bit to see if the feature is supported in the silicon.
if jtag.read_lc_ctrl_reg(&LcCtrlReg::TransitionCtrl)? < 2u32 {
let read = jtag.read_lc_ctrl_reg(&LcCtrlReg::TransitionCtrl)?;
if read < 2u32 && expect_raw_unlock_supported {
return Err(LcTransitionError::VolatileRawUnlockNotSupported.into());
} else if read >= 2u32 && !expect_raw_unlock_supported {
return Err(LcTransitionError::VolatileRawUnlockSupported.into());
}

// Select the requested JTAG TAP to connect to post-transition.
Expand All @@ -258,13 +270,21 @@ pub fn trigger_volatile_raw_unlock<'t>(
jtag = transport.jtag(jtag_params)?.connect(JtagTap::RiscvTap)?;
}

wait_for_status(
&mut *jtag,
Duration::from_secs(3),
LcCtrlStatus::TRANSITION_SUCCESSFUL,
)
.context("failed waiting for TRANSITION_SUCCESSFUL status.")?;

if expect_raw_unlock_supported {
wait_for_status(
&mut *jtag,
Duration::from_secs(3),
LcCtrlStatus::TRANSITION_SUCCESSFUL,
)
.context("failed waiting for TRANSITION_SUCCESSFUL status.")?;
} else {
let mut status = LcCtrlStatus::INITIALIZED | LcCtrlStatus::TOKEN_ERROR;
if use_external_clk {
status |= LcCtrlStatus::EXT_CLOCK_SWITCHED;
}
wait_for_status(&mut *jtag, Duration::from_secs(3), status)
.context("failed waiting for TOKEN_ERROR status.")?;
}
Ok(jtag)
}

Expand Down
3 changes: 3 additions & 0 deletions sw/host/opentitantool/src/command/lc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ impl CommandDispatch for VolatileRawUnlock {
/*use_external_clk=*/ true,
/*post_transition_tap=*/ JtagTap::LcTap,
&self.jtag_params,
// whether we expect the RAW unlock feature to be present or not.
// on prod silicon this should be disabled.
false,
)?;

jtag = self
Expand Down
6 changes: 6 additions & 0 deletions sw/host/tests/manuf/manuf_cp_volatile_unlock_raw/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ fn volatile_raw_unlock_with_reconnection_to_lc_tap(
/*use_external_clk=*/ true,
JtagTap::LcTap,
&opts.init.jtag_params,
// whether we expect the RAW unlock feature to be present or not.
// on prod silicon this should be disabled.
false,
)
.context("failed to transition to TEST_UNLOCKED0")?;

Expand Down Expand Up @@ -102,6 +105,9 @@ fn volatile_raw_unlock_with_reconnection_to_rv_tap(
/*use_external_clk=*/ true,
JtagTap::RiscvTap,
&opts.init.jtag_params,
// whether we expect the RAW unlock feature to be present or not.
// on prod silicon this should be disabled.
false,
)
.context("failed to transition to TEST_UNLOCKED0")?;

Expand Down

0 comments on commit db8f9b8

Please sign in to comment.