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/generate-ddr-memory-board-profiles.ts
/** Freeze explicit physical caches and current external package identity, without importing its adapter. */
import{readFileSync,writeFileSync,copyFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
import{auditRouteAngles}from'./check-route-angles'
import{compareDdrMemoryCachePathToBoard}from'./ddr-memory-cache-board-comparison'
const external=resolve(process.argv[2]??'/Users/ankan/Documents/Codex/2026-09-10/what-x20/outputs/mt41k512m8da-107-it-p-fanout'),accepted=resolve(process.argv[3]??'dist/ddr-nineteen-current-e3-web-repaired'),out=resolve('src/generated'),hashes:Record<string,string>={},hash=(s:string)=>createHash('sha256').update(s).digest('hex'),objectHash=(o:any)=>hash(JSON.stringify(o)),read=(p:string)=>{const s=readFileSync(p,'utf8');hashes[p]=hash(s);return s},json=(p:string)=>JSON.parse(read(p))
const pins=json(`${external}/src/pin-map.json`),footprint=read(`${external}/imports/MicronJlcFootprint.tsx`),api=read(`${external}/src/index.tsx`),pinApi=read(`${external}/src/pin-map.ts`),references=read(`${external}/src/ReferencePlanes.tsx`),hostApi=read(`${external}/src/am3352-host.ts`),report=json(`${accepted}/report.json`),candidate=json(`${accepted}/candidate.circuit.json`)
if(!report.accepted||report.candidateCircuitSha256!==objectHash(candidate)||pins.length!==78||pins.filter((p:any)=>p.routed).length!==72)throw Error('Source/accepted artifact mismatch')
const pads=[...footprint.matchAll(/<smtpad portHints=\{\["pin(\d+)"\]\} pcbX="([\d.\-]+)mm" pcbY="([\d.\-]+)mm" radius="([\d.]+)mm" shape="circle" \/>/g)].map(m=>({pin:Number(m[1]),x:Number(m[2]),y:Number(m[3]),radius:Number(m[4])}))
if(pads.length!==78||pins.some((p:any)=>!pads.some(q=>q.pin===p.pin&&q.x===p.x&&q.y===p.y&&q.radius===p.radius)))throw Error('Current footprint copper does not exactly match pin mapping')
const profiles=Object.fromEntries([0,1].map(byte=>{const paths=json(`${accepted}/ram-byte${byte}-facing-progress.trace-paths.json`),contract=json(`${accepted}/${byte?'ram-byte1-exit-contract':'exit-contract'}.json`),pathsHash=objectHash(paths),placement={x:-12,y:byte?6.5:-6.5,rotation:180};if(paths.length!==72||pins.filter((p:any)=>p.routed).some((pin:any)=>paths.filter((p:any)=>p.connection===`U1.ball_${pin.ball}`).length!==1)||!auditRouteAngles(paths).valid)throw Error('Invalid complete physical cache')
const overrides=paths.flatMap((path:any)=>{const pin=pins.find((p:any)=>path.connection===`U1.ball_${p.ball}`);if(!pin)throw Error('Unknown cached ball');return compareDdrMemoryCachePathToBoard(path,pin,byte,placement,candidate)})
return[`current_e3_byte${byte}`,{byte,layerSpace:'physical',layerCount:10,coordinateFrame:'package-center',paths,pathsSha256:pathsHash,placement,exitContract:contract,additionalBoardCopperOverrides:overrides}]
}))
const binding={schemaVersion:1,part:'MT41K512M8DA-107 IT:P',supplierPartNumbers:{jlcpcb:['C2888412']},externalSourceDirectory:external,acceptedArtifactDirectory:accepted,candidateCircuitSha256:objectHash(candidate),sourceFileHashes:hashes,profiles,scope:'Explicit board-profile escape override only. Current footprint/pin identity frozen; no external host adaptation or local reference pours. Full board still requires recorded power replacements, host routes, support components and global planes.'}
for(const[p,h]of Object.entries(hashes))if(hash(readFileSync(p,'utf8'))!==h)throw Error('Source changed during binding')
mkdirSync(out,{recursive:true});copyFileSync(`${external}/imports/MicronJlcFootprint.tsx`,`${out}/ddr-board-micron-footprint.tsx`);writeFileSync(`${out}/ddr-board-pin-map.json`,JSON.stringify(pins,null,2)+'\n');writeFileSync(`${out}/ddr-memory-board-profiles.json`,JSON.stringify(binding,null,2)+'\n');console.log(JSON.stringify(Object.fromEntries(Object.entries(profiles).map(([k,v]:any)=>[k,{paths:v.paths.length,boardOverrides:v.additionalBoardCopperOverrides.length,hash:v.pathsSha256}]))))