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/prepare-ddr-dq4-after-dq2.ts
/** Exact DQ2 replacement replay, then retire only DQ4 for isolated co-design. */
import{readFileSync,writeFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
import{auditCompositeHostTopology}from'./ddr-composite-routing-context'
const [dir,out]=process.argv.slice(2),read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),hash=(x:any)=>createHash('sha256').update(JSON.stringify(x)).digest('hex'),key=(e:any)=>`${e.type}:${e[`${e.type}_id`]}`
const m=read(resolve(dir,'original-copper-replacements.json')),parent=read(resolve(m.parentDirectory,'candidate.circuit.json')),candidate=read(resolve(dir,'candidate.circuit.json')),host=read(resolve(dir,'host-bundle.json')),input=read(resolve(m.parentDirectory,'routing-input.json')),report=read(resolve(m.parentDirectory,'report.json'))
if(hash(parent)!==m.parentCircuitSha256||hash(candidate)!==m.candidateCircuitSha256||m.captureHash!==host.captureHash||host.traces.length!==12)throw Error('DQ2 parent/candidate provenance differs')
const replay=new Map(parent.map((e:any)=>[key(e),e])),touched=new Set<string>()
for(const w of m.replacements){const k=key(w.before),afterKey=key(w.after);if(touched.has(k)||hash(replay.get(k))!==hash(w.before)||hash(w.before)!==w.beforeSha256||hash(w.after)!==w.afterSha256||(k!==afterKey&&replay.has(afterKey)))throw Error('Invalid exact DQ2 replacement');touched.add(k);replay.delete(k);replay.set(afterKey,w.after)}
if(replay.size!==candidate.length||candidate.some((e:any)=>hash(replay.get(key(e)))!==hash(e)))throw Error('Candidate has undeclared changes')
for(const t of host.traces)if(hash(candidate.find((e:any)=>e.type==='pcb_trace'&&e.pcb_trace_id===t.pcb_trace_id))!==hash(t))throw Error('Host differs')
const old=host.traces.find((t:any)=>t.connection_name==='source_trace_579');if(!old)throw Error('Missing DQ4 host')
const circuit=candidate.filter((e:any)=>e.pcb_trace_id!==old.pcb_trace_id),traces=host.traces.filter((t:any)=>t!==old),topology=auditCompositeHostTopology(circuit,traces,input.connections)
if(!topology.valid||topology.physical.connectivity.filter(c=>c.connected).length!==11)throw Error('Retained11 baseline failed')
mkdirSync(out,{recursive:true});for(const[n,v]of Object.entries({'candidate.circuit.json':circuit,'host-bundle.json':{...host,traces},'routing-input.json':input,'report.json':{...report,candidateCircuitSha256:hash(circuit),hostTracesSha256:hash(traces),physical:topology.physical},'invalidation.json':{parentDirectory:resolve(dir),parentSha256:hash(candidate),dq2ManifestSha256:hash(m),removed:old,allOtherElementsExact:true,topology}}))writeFileSync(resolve(out,n),JSON.stringify(v,null,2))