| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- param(
- [Parameter(Mandatory = $true)]
- [ValidateSet("PROGRAM_SRAM")]
- [string]$Confirm,
- [string]$TdRoot = "C:\Anlogic\TD_Release_2026.1_SP1.198.412"
- )
- Set-StrictMode -Version Latest
- $ErrorActionPreference = "Stop"
- $root = Split-Path -Parent $MyInvocation.MyCommand.Path
- $infoPath = Join-Path $root "package-info.json"
- $source = Join-Path $root "fw.bit"
- $info = Get-Content -LiteralPath $infoPath -Raw -Encoding UTF8 | ConvertFrom-Json
- $observed = (Get-FileHash -Algorithm SHA256 -LiteralPath $source).Hash.ToLowerInvariant()
- if ($observed -ne [string]$info.bitstream_sha256) { throw "bitstream hash mismatch" }
- if ([string]$info.commit -notmatch '^[0-9a-f]{40}$') { throw "package commit is invalid" }
- $active = @(Get-Process -ErrorAction SilentlyContinue | Where-Object {
- $_.ProcessName -in @("td", "bw", "bw_commands_prompt")
- })
- if ($active.Count -ne 0) {
- throw "TD or BitWriter process is already running; close it manually before programming"
- }
- $stage = Join-Path "C:\P2U" ([string]$info.commit)
- New-Item -ItemType Directory -Force -Path $stage | Out-Null
- $stagedBitstream = Join-Path $stage "fw.bit"
- Copy-Item -LiteralPath $source -Destination $stagedBitstream -Force
- if ((Get-FileHash -Algorithm SHA256 -LiteralPath $stagedBitstream).Hash.ToLowerInvariant() -ne $observed) {
- throw "staged bitstream hash mismatch"
- }
- $tcl = Join-Path $stage "program-sram.tcl"
- $log = Join-Path $stage "program-sram-console.log"
- $bitPath = $stagedBitstream.Replace('\', '/')
- [System.IO.File]::WriteAllText(
- $tcl,
- "connect_cable -allink`n" +
- "download -bit {$bitPath} -mode jtag -spd 2 -cable 0`n" +
- "exit`n",
- [System.Text.Encoding]::ASCII
- )
- $writer = Join-Path $TdRoot "bin\bw_commands_prompt.exe"
- if (-not (Test-Path -LiteralPath $writer -PathType Leaf)) { throw "BitWriter executable is missing" }
- $output = & $writer $tcl 2>&1 | Out-String
- [System.IO.File]::WriteAllText($log, $output, [System.Text.UTF8Encoding]::new($false))
- if ($LASTEXITCODE -ne 0) { throw "PROGRAM_SRAM failed; no retry was attempted" }
- [ordered]@{
- status = "pass"
- attempt_count = 1
- commit = [string]$info.commit
- bitstream_sha256 = $observed
- speed_hz = 200000
- next_command = ".\INITIALIZE_DISABLE.ps1"
- log = $log
- } | ConvertTo-Json -Compress
|