package_j6_host_sensor_real_fan_ptc_debug921.ps1 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. param(
  2. [string]$OutputDir = ".\j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2-epochfix-psarrayfix-tailfix-package",
  3. [string]$PackageName = "",
  4. [Parameter(Mandatory = $true)]
  5. [ValidateSet("temp-uart-ptc-remap")]
  6. [string]$Profile,
  7. [Parameter(Mandatory = $true)]
  8. [string]$Bitstream,
  9. [Parameter(Mandatory = $true)]
  10. [string]$TdReceipt,
  11. [switch]$ForceOverwrite
  12. )
  13. $ErrorActionPreference = "Stop"
  14. # Package profile:
  15. # temp-uart-ptc-remap -> j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2-epochfix-psarrayfix-tailfix
  16. # The copied collector is tools\remote\collect-j6-host-sensor-real-fan-ptc.ps1.
  17. # Start the collector first, then run manual PROGRAM_SRAM so READY/J6READY is captured.
  18. function Get-Sha256([string]$Path) {
  19. if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
  20. throw "File not found: $Path"
  21. }
  22. return (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant()
  23. }
  24. function Copy-IntoPackage([string]$Source, [string]$DestinationDir) {
  25. if (-not (Test-Path -LiteralPath $Source -PathType Leaf)) {
  26. throw "File not found: $Source"
  27. }
  28. New-Item -ItemType Directory -Force -Path $DestinationDir | Out-Null
  29. $name = Split-Path -Leaf $Source
  30. $destination = Join-Path $DestinationDir $name
  31. Copy-Item -LiteralPath $Source -Destination $destination -Force
  32. return $destination
  33. }
  34. function New-InventoryItem([string]$Path, [string]$Root) {
  35. $full = (Resolve-Path -LiteralPath $Path).Path
  36. $base = (Resolve-Path -LiteralPath $Root).Path.TrimEnd('\')
  37. $relative = $full.Substring($base.Length).TrimStart('\').Replace('\', '/')
  38. return [ordered]@{
  39. path = $relative
  40. sha256 = Get-Sha256 $full
  41. bytes = (Get-Item -LiteralPath $full).Length
  42. }
  43. }
  44. function New-PinMap([string]$SelectedProfile) {
  45. if ($SelectedProfile -ne "temp-uart-ptc-remap") {
  46. throw "Only temp-uart-ptc-remap is supported by this v2 packager"
  47. }
  48. return [ordered]@{
  49. name = "temp-uart-ptc-remap"
  50. bmc_tx_ball = "T4"
  51. bmc_rx_ball = "R5"
  52. host_tx_ball = "P7"
  53. host_rx_ball = "P8"
  54. debug_rx_ball = "P10"
  55. debug_tx_ball = "R10"
  56. ptc_substitutions = [ordered]@{
  57. PTC03 = [ordered]@{ original_ball = "T4"; substitute_ball = "P5"; bank_io_net = "BANK2_GPIO40" }
  58. PTC04 = [ordered]@{ original_ball = "R5"; substitute_ball = "T8"; bank_io_net = "BANK2_GPIO41" }
  59. PTC17 = [ordered]@{ original_ball = "P8"; substitute_ball = "M14"; bank_io_net = "BANK2_GPIO42" }
  60. PTC18 = [ordered]@{ original_ball = "P7"; substitute_ball = "M15"; bank_io_net = "BANK2_GPIO43" }
  61. PTC21 = [ordered]@{ original_ball = "P10"; substitute_ball = "P15"; bank_io_net = "BANK2_GPIO44" }
  62. PTC22 = [ordered]@{ original_ball = "R10"; substitute_ball = "N14"; bank_io_net = "BANK2_GPIO45" }
  63. }
  64. reserved_future_uart = [ordered]@{
  65. UART1_TX = [ordered]@{ fpga_ball = "L10"; bank_io_net = "BANK2_GPIO52"; used = $false }
  66. UART1_RX = [ordered]@{ fpga_ball = "M9"; bank_io_net = "BANK2_GPIO53"; used = $false }
  67. UART2_TX = [ordered]@{ fpga_ball = "M10"; bank_io_net = "BANK2_GPIO54"; used = $false }
  68. UART2_RX = [ordered]@{ fpga_ball = "N11"; bank_io_net = "BANK2_GPIO55"; used = $false }
  69. }
  70. }
  71. }
  72. function New-StartHereText([string]$SelectedProfile, [string]$BitName, [string]$TdName) {
  73. if ($SelectedProfile -ne "temp-uart-ptc-remap") {
  74. throw "Only temp-uart-ptc-remap is supported by this v2 packager"
  75. }
  76. $title = "J6 Host Sensor Real FAN/PTC temp-uart-ptc-remap Debug921 v2 epochfix psarrayfix tailfix"
  77. $wiring = @"
  78. - BMC UART:CPLD TX=T4,RX=R5。
  79. - DebugPort:COM7,P10/R10,921600 8N1。
  80. - HostPort:COM8,P7/P8,115200 8N1。
  81. - PTC03/PTC04/PTC17/PTC18/PTC21/PTC22 使用临时替代引脚;具体替代关系见 manifest.json。
  82. - HostPort 上电后先输出 `READY profile=temp-uart-ptc-remap seq=00000000`。collector 会等待 HostPort READY 和 DebugPort J6READY 都出现,保存 startup-preflight.json,再进入严格 12 条正式命令序列。
  83. "@
  84. $hardwareNote = "本 temp profile 保持当前三路调试串口接线不变,只把 6 路与串口冲突的 PTC 输出临时改到复核空闲 GPIO。"
  85. return @"
  86. # $title
  87. ## 1. 先启动 collector
  88. 在本包根目录打开 PowerShell,先复制执行下面这一条命令。collector 会先打开 COM8/COM7、等待 READY/J6READY,并把启动同步写入 `startup-preflight.json`。
  89. ~~~powershell
  90. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collector\collect-j6-host-sensor-real-fan-ptc.ps1 -HostPort COM8 -DebugPort COM7 -DurationSeconds 180 -OutputDir .\evidence-com8-host-com7-debug -Profile $SelectedProfile -Bitstream .\bitstreams\$BitName -TdReceipt .\td-receipts\$TdName
  91. ~~~
  92. 也可以执行包内快捷脚本:
  93. ~~~powershell
  94. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\commands\collect-template.ps1
  95. ~~~
  96. ## 2. collector 启动后手动刷 SRAM
  97. collector 开始等待后,在 TD/ChipWatcher 中只执行 `PROGRAM_SRAM`,选择下面这个 bitstream:
  98. ~~~text
  99. bitstreams/$BitName
  100. ~~~
  101. 不要执行任何非易失存储写入、擦除或固化存储相关动作。
  102. collector first, then PROGRAM_SRAM. collector 会忽略 READY/J6READY 前的旧程序 ACK,并在未锁定新 SRAM epoch 时拒绝发送正式命令。
  103. ## 接线
  104. $wiring
  105. ## 采集内容
  106. - HostPort 会发送 `SET PTC 01 10`、`SET PTC 24 20`、`SET FAN 01 40`、`SET FAN 04 30`、`SET PID ENABLE`、`GET STATUS`、`GET MAP`、三次 `GET SENSOR`、`SET PID DISABLE` 和 `DISABLE`。
  107. - `startup-preflight.json` 记录 `READY/J6READY` epoch 锁定和 pre-SRAM noise;正式 transcript 必须仍然只有 12 条命令和 12 条匹配 ACK。
  108. - DebugPort 只读,预期证据帧包括 `J6CMD/J6RAW/J6EVT/J6PWM/J6MOD/J6STAT/J6MAP/J6TEMP`。
  109. - collector 结束前会执行 tail drain,等待 DebugPort 静默并记录最后 `J6STAT` 是否覆盖最后完整 `J6RAW`;若末尾只有不完整行,会记录到 manifest/debug-frame-stream,不会当作有效 replay 帧。
  110. - BMC 温度仍来自 J6 UART raw 命令,不使用 I2C、MCU、`BMC_SCL/SDA` 或 `TEMP_SCL/SDA`。
  111. ## 包内参考
  112. - [中文 runbook](docs/j6-host-sensor-real-fan-ptc-debug921-runbook.zh-CN.md)
  113. - [collector 脚本](collector/collect-j6-host-sensor-real-fan-ptc.ps1)
  114. - [SHA256 inventory](sha256-inventory.json)
  115. ## 边界
  116. $hardwareNote
  117. 本包只声明 SRAM-only 诊断链路、HostPort 控制、BMC raw 采样、温度解析和证据采集成立;不声明非易失存储写入、真实热性能、真实 PTC/FAN 负载或 PID 闭环通过。
  118. "@
  119. }
  120. $repoRoot = Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..")
  121. $out = (Resolve-Path -LiteralPath (New-Item -ItemType Directory -Force -Path $OutputDir)).Path
  122. if ([string]::IsNullOrWhiteSpace($PackageName)) {
  123. $stamp = Get-Date -Format "yyyyMMdd-HHmmss"
  124. $PackageName = "j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2-epochfix-psarrayfix-tailfix-$stamp"
  125. }
  126. $stage = Join-Path $out $PackageName
  127. if (Test-Path -LiteralPath $stage) {
  128. if (-not $ForceOverwrite) {
  129. throw "Package staging directory already exists: $stage. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
  130. }
  131. $resolvedStage = (Resolve-Path -LiteralPath $stage).Path
  132. $resolvedOut = (Resolve-Path -LiteralPath $out).Path.TrimEnd('\')
  133. if (-not $resolvedStage.StartsWith($resolvedOut, [System.StringComparison]::OrdinalIgnoreCase)) {
  134. throw "Refusing to remove package directory outside output dir: $resolvedStage"
  135. }
  136. Remove-Item -LiteralPath $resolvedStage -Recurse -Force
  137. }
  138. foreach ($dir in @("bitstreams", "td-receipts", "collector", "commands", "schemas", "docs", "config")) {
  139. New-Item -ItemType Directory -Force -Path (Join-Path $stage $dir) | Out-Null
  140. }
  141. $collectorPath = Join-Path $repoRoot "tools\remote\collect-j6-host-sensor-real-fan-ptc.ps1"
  142. $schemaPath = Join-Path $repoRoot "schemas\real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt.schema.json"
  143. $runbookPath = Join-Path $repoRoot "docs\j6-host-sensor-real-fan-ptc-debug921-runbook.zh-CN.md"
  144. $pinInventoryPath = Join-Path $repoRoot "config\pin_inventory.fcb_fpga_mcu0611.json"
  145. $bitstreamCopy = Copy-IntoPackage $Bitstream (Join-Path $stage "bitstreams")
  146. $tdReceiptCopy = Copy-IntoPackage $TdReceipt (Join-Path $stage "td-receipts")
  147. Copy-IntoPackage $collectorPath (Join-Path $stage "collector") | Out-Null
  148. Copy-IntoPackage $schemaPath (Join-Path $stage "schemas") | Out-Null
  149. Copy-IntoPackage $runbookPath (Join-Path $stage "docs") | Out-Null
  150. Copy-IntoPackage $pinInventoryPath (Join-Path $stage "config") | Out-Null
  151. $bitName = Split-Path -Leaf $bitstreamCopy
  152. $tdName = Split-Path -Leaf $tdReceiptCopy
  153. $template = @'
  154. & "$PSHOME\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File .\collector\collect-j6-host-sensor-real-fan-ptc.ps1 -HostPort COM8 -DebugPort COM7 -DurationSeconds 180 -OutputDir .\evidence-com8-host-com7-debug -Profile __PROFILE__ -Bitstream .\bitstreams\__BITSTREAM__ -TdReceipt .\td-receipts\__TD_RECEIPT__
  155. '@
  156. $template = $template.Replace("__PROFILE__", $Profile).Replace("__BITSTREAM__", $bitName).Replace("__TD_RECEIPT__", $tdName)
  157. Set-Content -LiteralPath (Join-Path $stage "commands\collect-template.ps1") -Encoding UTF8 -Value $template
  158. Set-Content -LiteralPath (Join-Path $stage "START-HERE.zh-CN.md") -Encoding UTF8 -Value (New-StartHereText $Profile $bitName $tdName)
  159. $hostControlCommands = @(
  160. "SET PTC 01 10",
  161. "SET PTC 24 20",
  162. "SET FAN 01 40",
  163. "SET FAN 04 30",
  164. "SET PID ENABLE",
  165. "GET STATUS",
  166. "GET MAP",
  167. "GET SENSOR",
  168. "GET SENSOR",
  169. "GET SENSOR",
  170. "SET PID DISABLE",
  171. "DISABLE"
  172. )
  173. $pinMap = New-PinMap $Profile
  174. $manifest = [ordered]@{
  175. schema = "j6-host-sensor-real-fan-ptc-debug921-package-manifest-v1"
  176. status = "pass"
  177. generated_at = (Get-Date).ToUniversalTime().ToString("o")
  178. package_name = $PackageName
  179. diagnostic_scope = "host_sensor_real_fan_ptc_debug921"
  180. pin_profile = $Profile
  181. programming_mode = "PROGRAM_SRAM"
  182. bitstream = [ordered]@{ path = "bitstreams/$bitName"; sha256 = Get-Sha256 $bitstreamCopy }
  183. td_receipt = [ordered]@{ path = "td-receipts/$tdName"; sha256 = Get-Sha256 $tdReceiptCopy }
  184. collector = [ordered]@{ path = "collector/collect-j6-host-sensor-real-fan-ptc.ps1"; profile_argument = $Profile }
  185. host_control_commands = $hostControlCommands
  186. startup_preflight = [ordered]@{
  187. expected_artifact = "startup-preflight.json"
  188. ready_line = "READY profile=temp-uart-ptc-remap seq=00000000"
  189. j6ready_line = "J6READY profile=temp-uart-ptc-remap"
  190. epoch_locked_required = $true
  191. formal_ack_count = 12
  192. }
  193. tail_drain = [ordered]@{
  194. expected_manifest_field = "debug_tail"
  195. expected_stream_field = "tail"
  196. purpose = "Close the DebugPort capture window so post-J6STAT complete J6RAW tail is attributed instead of misreported as frame loss."
  197. }
  198. pin_map = $pinMap
  199. real_fan_ptc_hardware_status = "not_run"
  200. remote_dependencies = "PowerShell and .NET SerialPort only; no remote dependency install."
  201. sha256_inventory_policy = "sha256-inventory.json excludes itself because it is self-referential; the package zip is sealed by the adjacent .zip.sha256.txt file."
  202. authority_boundary = "SRAM-only diagnostic package. It does not program nonvolatile memory, install drivers, enumerate unknown COM ports, write DebugPort, claim thermal performance, or claim PID closed-loop pass."
  203. }
  204. $manifestPath = Join-Path $stage "manifest.json"
  205. $manifest | ConvertTo-Json -Depth 64 | Set-Content -LiteralPath $manifestPath -Encoding UTF8
  206. $inventory = New-Object System.Collections.Generic.List[object]
  207. Get-ChildItem -LiteralPath $stage -Recurse -File | Sort-Object FullName | ForEach-Object {
  208. if ($_.Name -eq "sha256-inventory.json") {
  209. return
  210. }
  211. $inventory.Add((New-InventoryItem $_.FullName $stage)) | Out-Null
  212. }
  213. [ordered]@{
  214. schema = "j6-host-sensor-real-fan-ptc-debug921-package-sha256-inventory-v1"
  215. generated_at = (Get-Date).ToUniversalTime().ToString("o")
  216. self_hash_policy = "excluded_self_referential_file"
  217. inventory = $inventory
  218. } | ConvertTo-Json -Depth 32 | Set-Content -LiteralPath (Join-Path $stage "sha256-inventory.json") -Encoding UTF8
  219. $zipPath = Join-Path $out ($PackageName + ".zip")
  220. if (Test-Path -LiteralPath $zipPath) {
  221. if (-not $ForceOverwrite) {
  222. throw "Package zip already exists: $zipPath. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
  223. }
  224. Remove-Item -LiteralPath $zipPath -Force
  225. }
  226. $zipSidecar = $zipPath + ".sha256.txt"
  227. if (Test-Path -LiteralPath $zipSidecar) {
  228. if (-not $ForceOverwrite) {
  229. throw "Package zip sidecar already exists: $zipSidecar. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
  230. }
  231. Remove-Item -LiteralPath $zipSidecar -Force
  232. }
  233. Compress-Archive -Path (Join-Path $stage "*") -DestinationPath $zipPath -Force
  234. $zipSha = Get-Sha256 $zipPath
  235. Set-Content -LiteralPath $zipSidecar -Encoding ASCII -Value ("{0} {1}" -f $zipSha, (Split-Path -Leaf $zipPath))
  236. Write-Host "Wrote $stage"
  237. Write-Host "Wrote $zipPath"
  238. Write-Host ("SHA256 {0} {1}" -f $zipSha, $zipPath)