diff --git a/capture/capture_aes.py b/capture/capture_aes.py index 839cf3b9..eec78e4f 100755 --- a/capture/capture_aes.py +++ b/capture/capture_aes.py @@ -106,6 +106,9 @@ def setup(cfg: dict, project: Path): ) target = Target(target_cfg) + # Check target firmware. + target.check_fw_version("1.5") + # Init scope. scope_type = cfg["capture"]["scope_select"] diff --git a/capture/capture_hmac.py b/capture/capture_hmac.py index 2186741e..7f00e6c9 100755 --- a/capture/capture_hmac.py +++ b/capture/capture_hmac.py @@ -106,6 +106,9 @@ def setup(cfg: dict, project: Path): ) target = Target(target_cfg) + # Check target firmware. + target.check_fw_version("1.5") + # Init scope. scope_type = cfg["capture"]["scope_select"] diff --git a/capture/capture_ibex.py b/capture/capture_ibex.py index cb5a2632..bfa23992 100755 --- a/capture/capture_ibex.py +++ b/capture/capture_ibex.py @@ -94,6 +94,9 @@ def setup(cfg: dict, project: Path): ) target = Target(target_cfg) + # Check target firmware. + target.check_fw_version("1.5") + # Init scope. scope_type = cfg["capture"]["scope_select"] diff --git a/capture/capture_kmac.py b/capture/capture_kmac.py index fb850eba..14054eeb 100755 --- a/capture/capture_kmac.py +++ b/capture/capture_kmac.py @@ -110,6 +110,9 @@ def setup(cfg: dict, project: Path): ) target = Target(target_cfg) + # Check target firmware. + target.check_fw_version("1.5") + # Init scope. scope_type = cfg["capture"]["scope_select"] diff --git a/capture/capture_otbn.py b/capture/capture_otbn.py index c399d498..de3442fe 100755 --- a/capture/capture_otbn.py +++ b/capture/capture_otbn.py @@ -120,6 +120,9 @@ def setup(cfg: dict, project: Path): ) target = Target(target_cfg) + # Check target firmware. + target.check_fw_version("1.5") + # Init scope. scope_type = cfg["capture"]["scope_select"] diff --git a/capture/capture_sha3.py b/capture/capture_sha3.py index 5c733f9f..d4db3ce3 100755 --- a/capture/capture_sha3.py +++ b/capture/capture_sha3.py @@ -95,6 +95,9 @@ def setup(cfg: dict, project: Path): ) target = Target(target_cfg) + # Check target firmware. + target.check_fw_version("1.5") + # Init scope. scope_type = cfg["capture"]["scope_select"] diff --git a/fault_injection/fi_crypto.py b/fault_injection/fi_crypto.py index e12afab1..5f0d1dda 100755 --- a/fault_injection/fi_crypto.py +++ b/fault_injection/fi_crypto.py @@ -52,6 +52,9 @@ def setup(cfg: dict, project: Path): ) target = Target(target_cfg) + # Check target firmware. + target.check_fw_version("1.5") + # Init FI gear. fi_gear = FIGear(cfg) diff --git a/fault_injection/fi_ibex.py b/fault_injection/fi_ibex.py index 5c6d5ccd..a1cd14cf 100755 --- a/fault_injection/fi_ibex.py +++ b/fault_injection/fi_ibex.py @@ -52,6 +52,9 @@ def setup(cfg: dict, project: Path): ) target = Target(target_cfg) + # Check target firmware. + target.check_fw_version("1.5") + # Init FI gear. fi_gear = FIGear(cfg) diff --git a/fault_injection/fi_otbn.py b/fault_injection/fi_otbn.py index 47449514..86a8eade 100755 --- a/fault_injection/fi_otbn.py +++ b/fault_injection/fi_otbn.py @@ -52,6 +52,9 @@ def setup(cfg: dict, project: Path): ) target = Target(target_cfg) + # Check target firmware. + target.check_fw_version("1.5") + # Init FI gear. fi_gear = FIGear(cfg) diff --git a/fault_injection/fi_rng.py b/fault_injection/fi_rng.py index e079db3b..d7c5b968 100755 --- a/fault_injection/fi_rng.py +++ b/fault_injection/fi_rng.py @@ -52,6 +52,9 @@ def setup(cfg: dict, project: Path): ) target = Target(target_cfg) + # Check target firmware. + target.check_fw_version("1.5") + # Init FI gear. fi_gear = FIGear(cfg) diff --git a/target/cw_fpga.py b/target/cw_fpga.py index 3a1e5a46..7eb709fa 100644 --- a/target/cw_fpga.py +++ b/target/cw_fpga.py @@ -224,3 +224,15 @@ def reset_target(self): io.pin_set_state("USB_A14", 1) # Add a small delay to allow OpenTitan to boot up. time.sleep(0.1) + + def check_fw_version(self, min_version: str): + """Checks whether the SAM3X CW310 FW matches the expected version. """ + major_min, minor_min = min_version.split(".") + target = cw.target(None, cw.targets.CW310) + fw = target.latest_fw + if fw["major"] < int(major_min) or fw["minor"] < int(minor_min): + print(f'Error: CW310 SAM3X FW is {str(fw["major"])}.{str(fw["minor"])} ' + f'should be {min_version}. Check the CW310 manual for updating the firmware.') + return False + else: + return True diff --git a/target/targets.py b/target/targets.py index 351277a1..7d423c95 100644 --- a/target/targets.py +++ b/target/targets.py @@ -126,3 +126,9 @@ def is_done(self): return self.target.target.is_done() else: return True + + def check_fw_version(self, min_version: str): + """Check if target CW is >= min:version. Only for CW310 FPGA.""" + if self.target_cfg.target_type == "cw310": + if not self.target.check_fw_version(min_version): + raise RuntimeError("Error: Please upgrade target firmware!")