From 39ed6b3bee172b5dcac57dd67d0e39e79f929c69 Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Tue, 9 Jul 2024 11:08:43 +0100 Subject: [PATCH] [otbn,dv] Tidy up how we handle "start-of-time RMA" in model Signed-off-by: Rupert Swarbrick --- hw/ip/otbn/dv/otbnsim/sim/sim.py | 2 +- hw/ip/otbn/dv/otbnsim/sim/state.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/ip/otbn/dv/otbnsim/sim/sim.py b/hw/ip/otbn/dv/otbnsim/sim/sim.py index 9a16daa0fe3cc8..8696e11d95eb98 100644 --- a/hw/ip/otbn/dv/otbnsim/sim/sim.py +++ b/hw/ip/otbn/dv/otbnsim/sim/sim.py @@ -346,7 +346,7 @@ def _step_pre_wipe(self, verbose: bool) -> StepRes: # complex might not be up, so we don't want to wait for a seed. Handle # this by jumping straight to the WIPING state and setting the number # of rounds to 1 (so that we don't wait again for a seed afterwards) - if self.state.rma_req == LcTx.ON and self.state.wipe_rounds_done == 0: + if self.state.rma_req == LcTx.ON and not self.state.edn_seen_running: self.state.lock_after_wipe = True self.state.wipe_rounds_to_do = 1 self.state.set_fsm_state(FsmState.WIPING) diff --git a/hw/ip/otbn/dv/otbnsim/sim/state.py b/hw/ip/otbn/dv/otbnsim/sim/state.py index ce7e620b5af016..4da66b62f2d985 100644 --- a/hw/ip/otbn/dv/otbnsim/sim/state.py +++ b/hw/ip/otbn/dv/otbnsim/sim/state.py @@ -175,6 +175,13 @@ def __init__(self) -> None: # in IDLE. self.delayed_lock = False + # We set this flag when the first URND seed comes back from the EDN. If + # we get an RMA request before this flag is set, we'll be in the + # PRE_WIPE state and the EDN might not actually be running. In that + # situation, we do a shortened secure wipe (just one round and no + # random data). + self.edn_seen_running = False + def get_next_pc(self) -> int: if self._pc_next_override is not None: return self._pc_next_override @@ -217,6 +224,8 @@ def urnd_completed(self) -> None: # it back into four 64-bit words. w64s = [(w256 >> (64 * i)) & ((1 << 64) - 1) for i in range(4)] + self.edn_seen_running = True + self.wsrs.URND.set_seed(w64s) def start_init_sec_wipe(self) -> None: