PROGRAM_SRAM.ps1 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. param(
  2. [Parameter(Mandatory = $true)]
  3. [ValidateSet("PROGRAM_SRAM")]
  4. [string]$Confirm,
  5. [string]$TdRoot = "C:\Anlogic\TD_Release_2026.1_SP1.198.412"
  6. )
  7. Set-StrictMode -Version Latest
  8. $ErrorActionPreference = "Stop"
  9. $root = Split-Path -Parent $MyInvocation.MyCommand.Path
  10. $infoPath = Join-Path $root "package-info.json"
  11. $source = Join-Path $root "fw.bit"
  12. $info = Get-Content -LiteralPath $infoPath -Raw -Encoding UTF8 | ConvertFrom-Json
  13. $observed = (Get-FileHash -Algorithm SHA256 -LiteralPath $source).Hash.ToLowerInvariant()
  14. if ($observed -ne [string]$info.bitstream_sha256) { throw "bitstream hash mismatch" }
  15. if ([string]$info.commit -notmatch '^[0-9a-f]{40}$') { throw "package commit is invalid" }
  16. $active = @(Get-Process -ErrorAction SilentlyContinue | Where-Object {
  17. $_.ProcessName -in @("td", "bw", "bw_commands_prompt")
  18. })
  19. if ($active.Count -ne 0) {
  20. throw "TD or BitWriter process is already running; close it manually before programming"
  21. }
  22. $stage = Join-Path "C:\P2U" ([string]$info.commit)
  23. New-Item -ItemType Directory -Force -Path $stage | Out-Null
  24. $stagedBitstream = Join-Path $stage "fw.bit"
  25. Copy-Item -LiteralPath $source -Destination $stagedBitstream -Force
  26. if ((Get-FileHash -Algorithm SHA256 -LiteralPath $stagedBitstream).Hash.ToLowerInvariant() -ne $observed) {
  27. throw "staged bitstream hash mismatch"
  28. }
  29. $tcl = Join-Path $stage "program-sram.tcl"
  30. $log = Join-Path $stage "program-sram-console.log"
  31. $bitPath = $stagedBitstream.Replace('\', '/')
  32. [System.IO.File]::WriteAllText(
  33. $tcl,
  34. "connect_cable -allink`n" +
  35. "download -bit {$bitPath} -mode jtag -spd 2 -cable 0`n" +
  36. "exit`n",
  37. [System.Text.Encoding]::ASCII
  38. )
  39. $writer = Join-Path $TdRoot "bin\bw_commands_prompt.exe"
  40. if (-not (Test-Path -LiteralPath $writer -PathType Leaf)) { throw "BitWriter executable is missing" }
  41. $output = & $writer $tcl 2>&1 | Out-String
  42. [System.IO.File]::WriteAllText($log, $output, [System.Text.UTF8Encoding]::new($false))
  43. if ($LASTEXITCODE -ne 0) { throw "PROGRAM_SRAM failed; no retry was attempted" }
  44. [ordered]@{
  45. status = "pass"
  46. attempt_count = 1
  47. commit = [string]$info.commit
  48. bitstream_sha256 = $observed
  49. speed_hz = 200000
  50. next_command = ".\INITIALIZE_DISABLE.ps1"
  51. log = $log
  52. } | ConvertTo-Json -Compress