Skip to content

Commit

Permalink
[fi] Enable inputs for OTBN tests
Browse files Browse the repository at this point in the history
Some OTBN FI tests require an input. This commit adds the possibility
of sending additional payload to the device, if required by the test.

Signed-off-by: Pascal Nasahl <[email protected]>
  • Loading branch information
nasahlpa committed Dec 6, 2024
1 parent 58657c0 commit 1789c8c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fault_injection/fi_otbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,27 @@ def fi_parameter_sweep(cfg: dict, target: Target, fi_gear,
fi_results = []
# Start the parameter sweep.
remaining_iterations = fi_gear.get_num_fault_injections()
# Helper variable tracking whether we already transmitted the test config
# if one exists.
config_transmitted = False
with tqdm(total=remaining_iterations, desc="Injecting", ncols=80,
unit=" different faults") as pbar:
while remaining_iterations > 0:
# Get fault parameters (e.g., trigger delay, glitch voltage).
fault_parameters = fi_gear.generate_fi_parameters()
# Arm the FI gear.
fi_gear.arm_trigger(fault_parameters)

# Start test on OpenTitan.
ot_communication.start_test(cfg)
# Send initial config to the device. Only needed at the first run
# after a reset.
if "config" in cfg["test"] and config_transmitted is False:
ot_communication.write_payload(cfg["test"]["config"])
config_transmitted = True
# Send payload to device, if test requires an input.
if "input" in cfg["test"]:
ot_communication.write_payload(cfg["test"]["input"])

# Read response.
response = ot_communication.read_response()
Expand All @@ -138,6 +150,8 @@ def fi_parameter_sweep(cfg: dict, target: Target, fi_gear,
ot_communication.init_keymgr(cfg["test"]["which_test"])
# Reset FIGear if necessary.
fi_gear.reset()
# Trigger re-write of initial config at next run.
config_transmitted = False
else:
# If the test decides to ignore alerts triggered by the alert
# handler, remove it from the received and expected response.
Expand Down
8 changes: 8 additions & 0 deletions target/communication/fi_otbn_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ def start_test(self, cfg: dict) -> None:
test_function = getattr(self, cfg["test"]["which_test"])
test_function()

def write_payload(self, payload: dict) -> None:
""" Send test payload to OpenTitan.
Args:
payload: The data to send to the target.
"""
time.sleep(0.01)
self.target.write(json.dumps(payload).encode("ascii"))

def read_response(self, max_tries: Optional[int] = 1) -> str:
""" Read response from Otbn FI framework.
Args:
Expand Down

0 comments on commit 1789c8c

Please sign in to comment.