Files
CoCo3_Plus_MiSTer/tools/audit_timing.py
T
bholman cb40fed3b9 Introduce Coco 3 Plus for MiSTer
Add original-firmware Sound & Speech, four configurable Multi-Pak sockets,
bounded per-slot ROM allocation and a nine-page menu organized around devices
and media. Repair inherited clock/reset/CPU-memory/video paths and add explicit
conditional external-I/O timing contracts. Preserve native Main startup-file
ordering, saved layouts, stock-core separation and the coco3plus media profile.

Provide native Windows tool downloads, pinned ToolShed ROM assembly, fresh
Quartus builds, functional and fitted timing checks, reviewed release packaging
and passwordless SSH installation with backups. Retain original component
notices, document contribution copyright and keep SSC ROM inputs outside Git.

Validation: Quartus17.0.2 Build602 seed5, zero errors; 15 functional jobs,
368 both-corner timing scopes and eight tooling-integrity checks pass.
The renamed build reaches Disk BASIC, PRINT1+1 returns2 and SSC loads ready.
Physical cold power cycling and conditional board-delay assumptions remain
separate. Full original upstream histories are preserved before this single
consolidated implementation commit.
2026-11-18 16:00:45 -07:00

69 lines
5.4 KiB
Python

#!/usr/bin/env python3
"""Audit actual fitted timing paths without treating empty scopes as passes."""
import argparse,hashlib,json,re,subprocess
from pathlib import Path
from timing_coverage import parse_ucp,classify
ROOT=Path(__file__).resolve().parents[1]
AUDITS=('bh_mpi_timing','nmi_timing_paths','uart_timing_paths','reset_cpu_timing_paths','video_timing_paths','ssc_integrated_timing','external_io_timing')
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
def main():
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('--quartus',type=Path,required=True,help='quartus_sta 17.0.2')
p.add_argument('--build',type=Path,default=ROOT/'build/fpga')
p.add_argument('--output',type=Path,default=ROOT/'build/timing')
p.add_argument('--resume',action='store_true',help='Reuse complete native logs; recheck all report hashes/paths')
a=p.parse_args();a.build=a.build.resolve();a.output=a.output.resolve()
if not a.output.is_relative_to(ROOT/'build'):p.error('Use an output inside build/')
build=json.loads((a.build/'build.json').read_text());project=a.build/'project'
if not build.get('passed'):raise RuntimeError('Full fit with nonnegative summary required')
for n,h in build['inputs'].items():
if sha(project/n)!=h or sha(ROOT/n)!=h:raise RuntimeError('Fitted/current input differs: '+n)
identity=dict(rbf_sha256=build['rbf_sha256'],inputs=build['inputs'],
fitted_sof_sha256=sha(project/'output_files/CoCo3.sof'),
scripts={name:sha(ROOT/'scripts'/(name+'.tcl')) for name in AUDITS})
if a.output.exists() and not a.resume:raise RuntimeError('Preserve earlier diagnostics; choose a fresh output')
a.output.mkdir(parents=True,exist_ok=True)
identity_file=a.output/'audit-input.json'
if a.resume:
if not identity_file.is_file() or json.loads(identity_file.read_text())!=identity:raise RuntimeError('Resumed audit does not match the fitted build and original scripts')
else:identity_file.write_text(json.dumps(identity,indent=2)+'\n')
results={}
for script in AUDITS:
out=a.output/script;log=a.output/(script+'.log')
print('AUDIT '+script,flush=True)
if not a.resume:
if log.exists() or out.exists():raise RuntimeError('Existing partial audit: '+script)
with log.open('w') as f:subprocess.run([str(a.quartus.resolve()),'-t',str(ROOT/'scripts'/(script+'.tcl')),str(project/'CoCo3'),'CoCo3',str(out)],stdout=f,stderr=subprocess.STDOUT,cwd=ROOT,check=True)
text=log.read_text(errors='replace')
if 'Quartus Prime TimeQuest Timing Analyzer was successful. 0 errors' not in text:raise RuntimeError('Incomplete native audit: '+script)
reports={};empty=[]
for path in sorted(out.glob('*.rpt')):
name=path.name
if not re.search(r'-(setup|hold|recovery|removal)\.rpt$',name):continue
if script=='external_io_timing':
expected=['sdram_dq-in','sdram_dq-out','sdram_command-out','hdmi-scaled','hdmi-direct','hdmi_audio-out','mcp_i2c-in','mcp_i2c-out','pixel-in','pixel-out','global']
if not any(name.startswith(n+'-') for n in expected):continue
values=[float(x) for x in re.findall(r'Worst case slack is ([-\d.]+)',path.read_text(errors='replace'))]
if any(x<0 for x in values):raise RuntimeError('Negative fitted timing: '+script+'/'+name)
if not values:
# Only asynchronous checks on synchronous-only subscopes may be empty.
if name.startswith('global-') or not re.search(r'-(recovery|removal)\.rpt$',name):raise RuntimeError('Empty substantive timing scope: '+script+'/'+name)
empty.append(name)
reports[name]=dict(slack_ns=min(values) if values else None,sha256=sha(path))
if script=='bh_mpi_timing' and len(reports)!=34:raise RuntimeError('MPI report inventory incomplete')
if script=='external_io_timing' and len(reports)!=48:raise RuntimeError('External report inventory incomplete')
if script=='ssc_integrated_timing' and len(reports)!=144:raise RuntimeError('SSC report inventory incomplete')
if script=='video_timing_paths' and len(reports)!=24:raise RuntimeError('Video report inventory incomplete')
if not reports:raise RuntimeError('No substantive report inventory: '+script)
results[script]=dict(reports=reports,empty_synchronous_async_checks=empty,log_sha256=sha(log),script_sha256=sha(ROOT/'scripts'/(script+'.tcl')))
if sha(project/'output_files/CoCo3.rbf')!=build['rbf_sha256']:raise RuntimeError('RBF changed during audit')
ucp=a.output/'external_io_timing/unconstrained.rpt'
counts,inventory=parse_ucp(ucp)
contracts={direction:{name:classify(name) for name in pins} for direction,pins in inventory.items()}
if any('UNCLASSIFIED' in value for pins in contracts.values() for value in pins.values()):raise RuntimeError('Unclassified remaining pin contract')
receipt=dict(audit_identity=identity,unconstrained_counts=counts,remaining_pin_contracts=contracts,coverage_sha256=sha(ucp),passed=True,rbf_sha256=build['rbf_sha256'],inputs=build['inputs'],audits=results,
scope='Both-corner fitted path audits under conditional SDRAM/PCB profile; not complete physical-board qualification',whole_board_electrically_qualified=False)
(a.output/'result.json').write_text(json.dumps(receipt,indent=2)+'\n')
print('PASS '+str(sum(len(v['reports']) for v in results.values()))+' fitted report scopes')
if __name__=='__main__':main()