|
|
@@ -299,13 +299,76 @@ def warning_audit(stage_records: dict[str, dict[str, object]]) -> dict[str, obje
|
|
|
}
|
|
|
|
|
|
|
|
|
+def timing_result(metrics: dict[str, object]) -> tuple[list[str], bool]:
|
|
|
+ required_metrics = (
|
|
|
+ "total_luts", "lut", "registers", "dsp", "eram_bram", "mslice",
|
|
|
+ "lslice", "packed_slices", "fmax_mhz", "setup_slack_ns", "hold_slack_ns",
|
|
|
+ "setup_total_negative_slack_ns", "hold_total_negative_slack_ns",
|
|
|
+ )
|
|
|
+ missing_metrics = [name for name in required_metrics if metrics[name] is None]
|
|
|
+ timing_pass = bool(
|
|
|
+ not missing_metrics
|
|
|
+ and metrics["violation_endpoint_counts"]
|
|
|
+ and metrics["all_violation_endpoint_counts_zero"]
|
|
|
+ and metrics["fmax_mhz"] >= 25.0
|
|
|
+ and metrics["setup_slack_ns"] >= 0.0
|
|
|
+ and metrics["hold_slack_ns"] >= 0.0
|
|
|
+ and metrics["setup_total_negative_slack_ns"] == 0.0
|
|
|
+ and metrics["hold_total_negative_slack_ns"] == 0.0
|
|
|
+ )
|
|
|
+ return missing_metrics,timing_pass
|
|
|
+
|
|
|
+
|
|
|
+def reaudit_receipt(path: Path, output: Path) -> int:
|
|
|
+ """Re-evaluate immutable native evidence; never overwrite the original receipt."""
|
|
|
+ path=path.resolve();output=output.resolve()
|
|
|
+ if output==ROOT or ROOT in output.parents or output==path.parent:
|
|
|
+ raise ValueError('reaudit output must be new and external')
|
|
|
+ old=json.loads(path.read_text(encoding='utf-8'))
|
|
|
+ if old.get('schema') not in ('prod2u-6400-td-receipt-v1','prod2u-mrdimm-td-receipt-v1'):
|
|
|
+ raise ValueError('unsupported native TD receipt schema')
|
|
|
+ profile=old['profile'];current=input_manifest(profile)
|
|
|
+ if current!=old['inputs']:raise ValueError('reaudit source inputs differ from the native build')
|
|
|
+ manifest_sha=hashlib.sha256(json.dumps(current,sort_keys=True,separators=(',',':')).encode()).hexdigest()
|
|
|
+ config=HARDWARE_PROFILES[profile];basename=config['artifact_basename']
|
|
|
+ if old['source_manifest_sha256']!=manifest_sha or old['project_sha256']!=current[config['project']] or old['source_closure_sha256']!=current[config['closure']]:
|
|
|
+ raise ValueError('reaudit input identity mismatch')
|
|
|
+ if old.get('simulation_only') is not False or old.get('production') is not True or old.get('missing_outputs'):
|
|
|
+ raise ValueError('reaudit requires a complete production native run')
|
|
|
+ expected={'syn':path.parent/f'syn/{basename}_gate.db','phy':path.parent/f'phy/{basename}_pr.db',
|
|
|
+ 'bitgen':path.parent/f'bitgen/{basename}.bit'}
|
|
|
+ for name in ('syn','phy','bitgen'):
|
|
|
+ stage=old['stages'][name];log=Path(stage['log'])
|
|
|
+ if stage['exit_code']!=0 or stage.get('timed_out') or not expected[name].is_file():
|
|
|
+ raise ValueError('reaudit cannot qualify an incomplete native stage: '+name)
|
|
|
+ if sha256(log)!=stage['log_sha256']:raise ValueError('native stage log changed: '+name)
|
|
|
+ if sha256(expected['bitgen'])!=old['bitstream_sha256']:raise ValueError('native bitstream changed')
|
|
|
+ audit=warning_audit(old['stages']);metrics=parse_metrics(path.parent,basename)
|
|
|
+ missing,timing=timing_result(metrics)
|
|
|
+ status='PASS' if audit['status']=='PASS' and timing else 'FAIL'
|
|
|
+ reviewed=dict(old)
|
|
|
+ reviewed.update(run_id=output.name,generated_at=datetime.now(timezone.utc).isoformat(),status=status,
|
|
|
+ warning_audit=audit,metrics=metrics,missing_metrics=missing,timing_pass_25mhz=timing,
|
|
|
+ deployment_status='TD_QUALIFIED_HARDWARE_NOT_RUN' if status=='PASS' else 'NOT_QUALIFIED')
|
|
|
+ reviewed['reaudit']={'native_run_id':old['run_id'],'native_receipt':str(path),
|
|
|
+ 'native_receipt_sha256':sha256(path),'original_status':old['status'],'reviewer_source':source_identity(ROOT),
|
|
|
+ 'reason':'current warning interpretation; native logs, inputs and bitstream verified and reused'}
|
|
|
+ output.mkdir(parents=True,exist_ok=False)
|
|
|
+ result=output/'td-receipt.json';result.write_text(json.dumps(reviewed,indent=2,sort_keys=True)+'\n')
|
|
|
+ print(str(result));return 0 if status=='PASS' else 1
|
|
|
+
|
|
|
+
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
|
parser = argparse.ArgumentParser()
|
|
|
parser.add_argument(
|
|
|
"--profile", choices=tuple(HARDWARE_PROFILES), default=DEFAULT_PROFILE
|
|
|
)
|
|
|
parser.add_argument("--run-root", type=Path)
|
|
|
+ parser.add_argument("--reaudit",type=Path,help="verify and re-audit an existing native run; no rebuild")
|
|
|
args = parser.parse_args(argv)
|
|
|
+ if args.reaudit:
|
|
|
+ if args.run_root is None:parser.error('--reaudit requires a new --run-root')
|
|
|
+ return reaudit_receipt(args.reaudit,args.run_root)
|
|
|
profile_name = args.profile
|
|
|
profile = HARDWARE_PROFILES[profile_name]
|
|
|
project_path = ROOT / str(profile["project"])
|
|
|
@@ -379,22 +442,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
status = "FAIL"
|
|
|
bitstream = expected["bitgen"]
|
|
|
metrics = parse_metrics(run_root, artifact_basename)
|
|
|
- required_metrics = (
|
|
|
- "total_luts", "lut", "registers", "dsp", "eram_bram", "mslice",
|
|
|
- "lslice", "packed_slices", "fmax_mhz", "setup_slack_ns", "hold_slack_ns",
|
|
|
- "setup_total_negative_slack_ns", "hold_total_negative_slack_ns",
|
|
|
- )
|
|
|
- missing_metrics = [name for name in required_metrics if metrics[name] is None]
|
|
|
- timing_pass = bool(
|
|
|
- not missing_metrics
|
|
|
- and metrics["violation_endpoint_counts"]
|
|
|
- and metrics["all_violation_endpoint_counts_zero"]
|
|
|
- and metrics["fmax_mhz"] >= 25.0
|
|
|
- and metrics["setup_slack_ns"] >= 0.0
|
|
|
- and metrics["hold_slack_ns"] >= 0.0
|
|
|
- and metrics["setup_total_negative_slack_ns"] == 0.0
|
|
|
- and metrics["hold_total_negative_slack_ns"] == 0.0
|
|
|
- )
|
|
|
+ missing_metrics,timing_pass=timing_result(metrics)
|
|
|
if not timing_pass:
|
|
|
status = "FAIL"
|
|
|
receipt = {
|