Skip to content

Commit

Permalink
[fi] Add OTFIRng
Browse files Browse the repository at this point in the history
  • Loading branch information
aewag committed Jun 3, 2024
1 parent cb9ce2e commit f1a5da5
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions target/communication/fi_rng_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
"""Communication interface for OpenTitan RNG FI framework.
Communication with OpenTitan happens over the uJSON command interface.
"""
import json
import time
from typing import Optional


from target.communication.otfi import OTFI
from target.communication.otfi_test import OTFITest


class OTFIRng(OTFI):
TESTS = [
OTFITest("csrng_bias"),
OTFITest("edn_bus_ack"),
]

def __init__(self, target) -> None:
super().__init__(target, "Rng")

def init(self, test: Optional[str] = "") -> None:
""" Initialize the RNG FI code on the chip.
Args:
test: The selected test.
Returns:
The device ID of the device.
"""
# RngFi command.
self._ujson_fi_cmd()
# Init command.
time.sleep(0.01)
if "csrng" in test:
self.target.write(json.dumps("CsrngInit").encode("ascii"))
else:
self.target.write(json.dumps("EdnInit").encode("ascii"))
# Read back device ID from device.
return self.read_response(max_tries=30)

0 comments on commit f1a5da5

Please sign in to comment.