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/rebind-ddr-support-parent.ts
/** Rebind support evidence only when parent candidate, host and routing inputs are byte-identical. */
import{readFileSync,writeFileSync,cpSync,existsSync,readdirSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
const[oldArg,newArg,supportArg,outArg]=process.argv.slice(2);if(!outArg)throw Error('Usage: old-parent corrected-parent support output')
const old=resolve(oldArg!),next=resolve(newArg!),support=resolve(supportArg!),out=resolve(outArg!),fh=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex'),hash=(v:any)=>createHash('sha256').update(JSON.stringify(v)??'undefined').digest('hex'),read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),equalFiles=['candidate.circuit.json','host-bundle.json','routing-input.json'];if(existsSync(out))throw Error('Output exists')
for(const n of equalFiles)if(fh(old+'/'+n)!==fh(next+'/'+n))throw Error(`Geometry/check input differs: ${n}`)
const a=read(old+'/report.json'),b=read(next+'/report.json'),r=read(support+'/report.json'),m=read(support+'/original-copper-replacements.json');if(!r.accepted||m.parentDirectory!==old||r.parentCircuitSha256!==b.candidateCircuitSha256||r.candidateCircuitSha256!==hash(read(support+'/candidate.circuit.json')))throw Error('Support parent/candidate identity differs')
const changes:any[]=[];for(const k of new Set([...Object.keys(a),...Object.keys(b)])){if(hash(a[k])!==hash(b[k])){const inherited=hash(r[k])===hash(a[k]);changes.push({key:k,inherited,beforeHash:hash(a[k]),afterHash:hash(b[k])});if(inherited){if(k in b)r[k]=b[k];else delete r[k]}}}
cpSync(support,out,{recursive:true});const bindings=Object.fromEntries(readdirSync(next).filter(n=>n.endsWith('.json')).map(n=>[resolve(next,n),fh(resolve(next,n))]));m.parentDirectory=next;r.parentDirectory=next;r.originalCopperReplacementsSha256=hash(m);r.parentMetadataRebase={oldParentDirectory:old,correctedParentDirectory:next,byteIdenticalFiles:equalFiles.map(name=>({name,sha256:fh(next+'/'+name)})),changedReportFields:changes,correctedParentSourceHashes:bindings,scope:'Only inherited metadata rebound. Candidate and checked routing/host copper are unchanged; support validation is reused exactly.'};r.sourceHashes={...r.sourceHashes,...bindings};const sm=read(out+'/support-replacements.json');sm.parentDirectory=next
for(const[n,v]of [['report.json',r],['original-copper-replacements.json',m],['support-replacements.json',sm]] as const)writeFileSync(out+'/'+n,JSON.stringify(v,null,2)+'\n');for(const[p,h]of Object.entries(bindings))if(fh(p)!==h)throw Error('Corrected parent changed');console.log(JSON.stringify({candidateCircuitSha256:r.candidateCircuitSha256,accepted:r.accepted,correctedParent:next}))