0hmX/am3352
This code suite comprises TypeScript scripts that analyze, verify, and assemble complex DDR memory interface hardware, focusing on physical routing, via and pad placement, electrical clearance, and physical constraints, often involving precise geometric calculations and consistent provenance tracking.
- Version
- 1.0.5
- License
- unset
- Stars
- 0
scripts/merge-ddr-d3-partial-timing.ts
/** Final exact compatibility merge; no routing or source-profile mutation. */
import {readFileSync,writeFileSync,mkdirSync} from 'node:fs'
import {resolve} from 'node:path'
import {createHash} from 'node:crypto'
import {verifyDdrCapture} from './ddr-capture-provenance'
import {objectHash,validateDeclaredDdrReplacements} from './improve-ddr-a9-power-launches'
import {applyFacingExitReplacements} from './ddr-facing-context'
import {auditCompositeHostTopology} from './ddr-composite-routing-context'
import {auditDdrLocalEscapeContacts} from './audit-ddr-local-escape-contacts'
import {verifyDdrSystemCopper,auditDdrTraceJunctions} from './check-ddr-system-copper'
import {auditRouteAngles} from './check-route-angles'
import {checkHostTerminalContract} from './route-ddr-sequential'
const [capture,retuned,d3Dir,out]=process.argv.slice(2)
if(!capture||!retuned||!d3Dir||!out)throw Error('Usage: capture retuned-host-board prior-D3-artifact output')
const hashes:Record<string,string>={},hash=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex'),read=(p:string)=>{p=resolve(p);hashes[p]=hash(p);return JSON.parse(readFileSync(p,'utf8'))}
const {captureHash}=verifyDdrCapture(capture),parent=read(resolve(retuned,'candidate.circuit.json')),host=read(resolve(retuned,'host-bundle.json')),manifest=read(resolve(retuned,'original-copper-replacements.json')),retunedReport=read(resolve(retuned,'report.json')),base=read(resolve(manifest.parentDirectory,'candidate.circuit.json')),input=read(resolve(manifest.parentDirectory,'routing-input.json'))
if(!retunedReport.accepted||[manifest,host,retunedReport].some(x=>x.captureHash!==captureHash)||host.traces.length!==11)throw Error('Retuned input capture/count mismatch')
for(const[p,h]of Object.entries(manifest.inputHashes)){if(hash(p)!==h)throw Error(`Retuned provenance changed: ${p}`);hashes[resolve(p)]=h as string}
const retunedPreservation=validateDeclaredDdrReplacements(base,parent,manifest),prior=read(resolve(d3Dir,'report.json')),changes=read(resolve(d3Dir,'replacements.json')),priorCandidate=read(resolve(d3Dir,'candidate.circuit.json')),cache=read(resolve(d3Dir,'ram-byte0-facing-progress.trace-paths.json')),contract=read(resolve(d3Dir,'exit-contract.json'))
if(!prior.accepted||prior.captureHash!==captureHash||prior.parentCandidateSha256!==objectHash(base)||prior.candidateCircuitSha256!==objectHash(priorCandidate)||objectHash(applyFacingExitReplacements(base,changes))!==objectHash(priorCandidate)||prior.ramCacheSha256!==objectHash(cache)||changes.invalidatedHostTraces.length)throw Error('Exact D3 witness mismatch')
const candidate=applyFacingExitReplacements(parent,changes),trace=changes.traces[0].after,exit=changes.breakoutPoints[0].after,connections=input.connections.map((c:any)=>({...c,pointsToConnect:c.pointsToConnect.map((p:any)=>p.pointId===exit.pcb_breakout_point_id?{...p,x:exit.x,y:exit.y,layer:exit.layer}:p)}))
const fresh=[...host.traces,trace],freshIds=new Set(fresh.map((t:any)=>t.pcb_trace_id)),physical=verifyDdrSystemCopper(candidate.filter((e:any)=>!freshIds.has(e.pcb_trace_id)),fresh,connections,{}),topology=auditCompositeHostTopology(candidate,host.traces,connections),localContacts=auditDdrLocalEscapeContacts(candidate,trace,connections),allAngles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')),allJunctions=auditDdrTraceJunctions(candidate,connections),terminal=checkHostTerminalContract(host.traces,connections.filter((c:any)=>host.traces.some((t:any)=>t.connection_name===c.name)))
const hostPreserved=host.traces.every((t:any)=>objectHash(parent.find((e:any)=>e.pcb_trace_id===t.pcb_trace_id))===objectHash(t)&&objectHash(candidate.find((e:any)=>e.pcb_trace_id===t.pcb_trace_id))===objectHash(t))
const accepted=hostPreserved&&!physical.errors.length&&!physical.violations.length&&topology.valid&&localContacts.valid&&allAngles.valid&&allJunctions.valid&&terminal.valid&&cache.length===72&&auditRouteAngles(cache).valid&&contract.paddingChangeMm===0
verifyDdrCapture(capture);for(const[p,h]of Object.entries(hashes))if(hash(p)!==h)throw Error(`Input changed during merge: ${p}`)
mkdirSync(out,{recursive:true});const write=(p:string,x:any)=>writeFileSync(resolve(out,p),JSON.stringify(x,null,2)+'\n')
write('report.json',{captureHash,accepted,parentDirectory:resolve(retuned),parentCandidateSha256:objectHash(parent),parentCandidateFileSha256:hash(resolve(retuned,'candidate.circuit.json')),candidateCircuitSha256:objectHash(candidate),retunedPreservation,d3WitnessSha256:objectHash(changes),inputFileHashes:hashes,hostPreserved,retainedHosts:host.traces.length,physical,topology,localContacts,allAngles,allJunctions,terminal,ramCacheSha256:objectHash(cache),lengthBudget:prior.lengthBudget,scope:'Eleven retuned host paths unchanged, plus compatible unhosted D3 local escape. Partial byte0 timing only; no complete interface qualification.'})
if(accepted){write('candidate.circuit.json',candidate);write('host-bundle.json',host);write('routing-input.json',{...input,connections,traces:host.traces,obstacles:undefined});write('ram-byte0-facing-progress.trace-paths.json',cache);write('exit-contract.json',{...contract,candidateCircuitSha256:objectHash(candidate),scope:'Full 72-path experimental RAM0 cache; D3 still unhosted. Shortened/tuned DQS0, D4, DQ7 and remaining accepted hosts are preserved in board candidate.'});write('replacements.json',changes)}
console.log(JSON.stringify({accepted,hosts:host.traces.length,violations:physical.violations.length,topology:topology.valid,localContacts:localContacts.valid,cachePaths:cache.length}));if(!accepted)process.exitCode=1