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/improve-ddr-b9-shared-power-launches.ts
/** Explicit nested patch: validated ten-host baseline -> A9 power52 -> B9 power54. */
import{readFileSync,writeFileSync,mkdirSync,copyFileSync}from'node:fs'
import{resolve}from'node:path'
import{spawnSync}from'node:child_process'
import{objectHash,validateDeclaredDdrReplacements}from'./improve-ddr-a9-power-launches'
import{verifyDdrCapture}from'./ddr-capture-provenance'
import{loadDdrSupportRoutingContext}from'./ddr-support-routing-context'
import{verifyDdrSystemCopper}from'./check-ddr-system-copper'
import{refreshDdrPlaneContacts}from'./ddr-plane-contact-audit'
const read=(p:string)=>JSON.parse(readFileSync(p,'utf8'))
export function b9SharedRoute(start:any,via:{x:number;y:number}){
const dx=via.x-start.x,dy=via.y-start.y,d=Math.min(Math.abs(dx),Math.abs(dy))
const route=[structuredClone(start),{route_type:'wire',x:start.x+Math.sign(dx)*d,y:start.y+Math.sign(dy)*d,width:.12,layer:'top'},{route_type:'wire',x:via.x,y:via.y,width:.12,layer:'top'}]
const length=route.slice(1).reduce((sum,p,i)=>sum+Math.hypot(p.x-route[i].x,p.y-route[i].y),0)
if(start.layer!=='top'||length>1.524+1e-8||d<1e-8)throw Error('Unsupported short shared-via approach')
return{route,length}
}
export async function improveB9(parentDir:string,captureDir:string,outDir:string){
if(resolve(parentDir)===resolve(outDir))throw Error('Output must be isolated')
const parent=read(`${parentDir}/candidate.circuit.json`),prior=read(`${parentDir}/report.json`),parentManifest=read(`${parentDir}/original-copper-replacements.json`),host=read(`${parentDir}/host-bundle.json`),priorAudit=read(`${parentDir}/ram-power-launch-audit.json`)
const baselineDir=parentManifest.parentDirectory,baseline=read(`${baselineDir}/candidate.circuit.json`),original=read(`${captureDir}/unrouted.circuit.json`),connections=read(`${captureDir}/routing-input.json`).connections,{captureHash}=verifyDdrCapture(captureDir)
if(host.captureHash!==captureHash||prior.captureHash!==captureHash||parentManifest.captureHash!==captureHash||prior.originalCopperReplacementsSha256!==objectHash(parentManifest)||prior.launchAuditSha256!==objectHash(priorAudit)||priorAudit.launchQualified!==52)throw Error('Stale parent evidence')
const hostIds=new Set(host.traces.map((t:any)=>t.pcb_trace_id)),actualHosts=baseline.filter((e:any)=>e.type==='pcb_trace'&&hostIds.has(e.pcb_trace_id))
if(actualHosts.length!==host.traces.length||host.layerSpace!=='physical')throw Error('Host identity mismatch')
const baselineValidation=await loadDdrSupportRoutingContext(captureDir,`${baselineDir}/candidate.circuit.json`,original,actualHosts,captureHash),parentValidation=validateDeclaredDdrReplacements(baseline,parent,parentManifest)
const child=structuredClone(parent),replacements:any[]=[],sharedVias:any[]=[],changedIds=new Set<string>()
for(const byte of[0,1]){
const row=priorAudit.unresolved.find((r:any)=>r.byte===byte&&r.terminal==='VDDQ_B9'),a9=priorAudit.rows.find((r:any)=>r.byte===byte&&r.terminal==='VDD_A9')
if(!row||!a9?.launchWithin1524Mm||a9.connectionVia.annulusSamplesInPlane!==32)throw Error('Expected B9 unresolved and A9 plane contact')
const via=a9.connectionVia,users=priorAudit.rows.filter((r:any)=>r.connectionVia&&Math.hypot(r.connectionVia.x-via.x,r.connectionVia.y-via.y)<1e-7)
if(users.length!==1)throw Error('Sharing would exceed two balls per via')
const index=child.findIndex((e:any)=>e.type==='pcb_trace'&&e.pcb_trace_id===row.pcbTraceId),before=parent[index],source=parent.find((e:any)=>e.type==='source_trace'&&e.source_trace_id===before?.source_trace_id)
if(source?.name!==`RAM${byte}_VDDQ_B9_escape`)throw Error('B9 source identity mismatch')
const {route,length}=b9SharedRoute(before.route[0],via),after={...structuredClone(before),route,connectsTo:(before.connectsTo??[]).filter((id:string)=>!id.startsWith('pcb_breakout_point_'))}
delete after.connection_name
child[index]=after;changedIds.add(before.pcb_trace_id)
replacements.push({id:`pcb_trace:${before.pcb_trace_id}`,reason:'Connect B9 to existing same-rail A9 via with diagonal-first top approach; no additional via, at most two RAM balls per via.',beforeSha256:objectHash(before),afterSha256:objectHash(after),before,after})
sharedVias.push({byte,via:{x:via.x,y:via.y},ownerTraceId:a9.pcbTraceId,addedTraceId:before.pcb_trace_id,sourceTerminals:['VDD_A9','VDDQ_B9'],ramBallsPerVia:2,lengthMm:length,retiredBreakoutPointIds:(before.connectsTo??[]).filter((id:string)=>id.startsWith('pcb_breakout_point_'))})
}
const manifest={captureHash,parentDirectory:resolve(parentDir),parentCircuitSha256:objectHash(parent),candidateCircuitSha256:objectHash(child),parentManifestSha256:objectHash(parentManifest),replacements,sharedVias},supportValidation=validateDeclaredDdrReplacements(parent,child,manifest)
const fresh=child.filter((e:any)=>e.type==='pcb_trace'&&(hostIds.has(e.pcb_trace_id)||changedIds.has(e.pcb_trace_id))),freshIds=new Set(fresh.map((t:any)=>t.pcb_trace_id)),physical=verifyDdrSystemCopper(child.filter((e:any)=>e.type!=='pcb_trace'||!freshIds.has(e.pcb_trace_id)),fresh,connections,{})
if(physical.errors.length||physical.violations.length||!physical.angles.valid||physical.joinedBends.length)throw Error(`Full copper check failed ${JSON.stringify(physical)}`)
if(actualHosts.some((t:any)=>!physical.connectivity.some((c:any)=>c.name===t.connection_name&&c.connected)))throw Error('Host connectivity lost')
const planeAudit=refreshDdrPlaneContacts(prior.planeAudit,child.filter((e:any)=>e.type==='pcb_copper_pour'),child)
mkdirSync(outDir,{recursive:true});const write=(n:string,v:any)=>writeFileSync(`${outDir}/${n}`,JSON.stringify(v,null,2))
write('candidate.circuit.json',child);copyFileSync(`${parentDir}/host-bundle.json`,`${outDir}/host-bundle.json`);write('original-copper-replacements.json',manifest)
const report={...prior,parentReportSha256:objectHash(prior),supportValidationChain:{baseline:baselineValidation.evidence,parent:parentValidation,child:supportValidation,parentManifestSha256:objectHash(parentManifest)},supportValidation,originalCopperReplacementsSha256:objectHash(manifest),planeAudit,physical,externalAliasesUsed:false,scope:'Two B9 shared-via trace replacements atop explicitly validated A9 power52 patch. All parent hosts, support components, planes and existing vias exact. Actual source audit required; not complete DDR signoff.'}
write('report.json',report)
const run=spawnSync(process.execPath,[resolve(import.meta.dir,'audit-ddr-global-power-launches.ts'),outDir,captureDir],{encoding:'utf8'});if(run.status!==0)throw Error(run.stderr)
const audit=read(`${outDir}/ram-power-launch-audit.json`)
if(audit.launchQualified!==54||audit.planeConnected!==54||audit.total!==60||priorAudit.rows.some((r:any)=>r.launchWithin1524Mm&&!audit.rows.some((n:any)=>n.byte===r.byte&&n.ball===r.ball&&n.launchWithin1524Mm)))throw Error('Actual source audit did not preserve52 and prove54')
for(const v of sharedVias)if(audit.rows.filter((r:any)=>r.connectionVia&&Math.hypot(r.connectionVia.x-v.via.x,r.connectionVia.y-v.via.y)<1e-7).length!==2)throw Error('Actual shared-via ball count differs')
Object.assign(report,{launchAuditSha256:objectHash(audit),launchQualified:54});write('report.json',report)
return{output:resolve(outDir),candidateCircuitSha256:objectHash(child),launchQualified:54,total:60,sharedVias,physical:{errors:physical.errors.length,violations:physical.violations.length,anglesValid:physical.angles.valid,joinedBends:physical.joinedBends.length,connected:physical.connectivity.filter((c:any)=>c.connected).length,minClearanceMm:physical.minClearanceMm}}
}
if(import.meta.main){const [parent='dist/ddr-integrated-ten-power52',capture='dist/ddr-system/host-taps-54af3e346b5e',out='dist/ddr-integrated-ten-power54']=process.argv.slice(2);console.log(JSON.stringify(await improveB9(parent,capture,out),null,2))}