package_j6_host_sensor_real_fan_ptc_debug921.ps1 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. param(
  2. [string]$OutputDir = ".\j6tmp-v2-tailfix-package",
  3. [string]$PackageName = "",
  4. [Parameter(Mandatory = $true)]
  5. [ValidateSet("temp-uart-ptc-remap", "debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")]
  6. [string]$Profile,
  7. [string]$Bitstream = "",
  8. [Parameter(Mandatory = $true)]
  9. [string]$TdReceipt,
  10. [switch]$FormalBlocked,
  11. [switch]$ForceOverwrite
  12. )
  13. $ErrorActionPreference = "Stop"
  14. # Package profile:
  15. # temp-uart-ptc-remap -> j6tmp-v2-tailfix
  16. # debug-photo-uart-bmc-replay/formal-uart1-bmc-replay -> j6-bmc-replay package profiles
  17. # The copied collector is tools\remote\collect-j6-host-sensor-real-fan-ptc.ps1.
  18. # The copied BMC replay helper is tools\bmc_replay_uart.py.
  19. # Start BMC replay first, then collector, then manual PROGRAM_SRAM so READY/J6READY is captured.
  20. $ShortBitName = "j6tmp.bit"
  21. $ShortTdName = "td.json"
  22. function Get-Sha256([string]$Path) {
  23. if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
  24. throw "File not found: $Path"
  25. }
  26. return (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant()
  27. }
  28. function Get-StringSha256([string]$Text) {
  29. $sha = [System.Security.Cryptography.SHA256]::Create()
  30. try {
  31. $bytes = [System.Text.Encoding]::ASCII.GetBytes($Text)
  32. $hash = $sha.ComputeHash($bytes)
  33. return ([System.BitConverter]::ToString($hash)).Replace("-", "").ToLowerInvariant()
  34. } finally {
  35. $sha.Dispose()
  36. }
  37. }
  38. function Copy-IntoPackage([string]$Source, [string]$DestinationDir) {
  39. if (-not (Test-Path -LiteralPath $Source -PathType Leaf)) {
  40. throw "File not found: $Source"
  41. }
  42. New-Item -ItemType Directory -Force -Path $DestinationDir | Out-Null
  43. $name = Split-Path -Leaf $Source
  44. $destination = Join-Path $DestinationDir $name
  45. Copy-Item -LiteralPath $Source -Destination $destination -Force
  46. return $destination
  47. }
  48. function New-InventoryItem([string]$Path, [string]$Root) {
  49. $full = (Resolve-Path -LiteralPath $Path).Path
  50. $base = (Resolve-Path -LiteralPath $Root).Path.TrimEnd('\')
  51. $relative = $full.Substring($base.Length).TrimStart('\').Replace('\', '/')
  52. return [ordered]@{
  53. path = $relative
  54. sha256 = Get-Sha256 $full
  55. bytes = (Get-Item -LiteralPath $full).Length
  56. }
  57. }
  58. function New-PinMap([string]$SelectedProfile) {
  59. $commonReservedFutureUart = [ordered]@{
  60. UART1_TX = [ordered]@{ fpga_ball = "L10"; bank_io_net = "BANK2_GPIO52"; used = ($SelectedProfile -eq "formal-uart1-bmc-replay") }
  61. UART1_RX = [ordered]@{ fpga_ball = "M9"; bank_io_net = "BANK2_GPIO53"; used = ($SelectedProfile -eq "formal-uart1-bmc-replay") }
  62. UART2_TX = [ordered]@{ fpga_ball = "M10"; bank_io_net = "BANK2_GPIO54"; used = ($SelectedProfile -eq "formal-uart1-bmc-replay") }
  63. UART2_RX = [ordered]@{ fpga_ball = "N11"; bank_io_net = "BANK2_GPIO55"; used = ($SelectedProfile -eq "formal-uart1-bmc-replay") }
  64. }
  65. if ($SelectedProfile -eq "temp-uart-ptc-remap") {
  66. return [ordered]@{
  67. name = "temp-uart-ptc-remap"
  68. bmc_tx_ball = "T4"
  69. bmc_rx_ball = "R5"
  70. host_tx_ball = "P7"
  71. host_rx_ball = "P8"
  72. debug_rx_ball = "P10"
  73. debug_tx_ball = "R10"
  74. ptc_substitutions = [ordered]@{
  75. PTC03 = [ordered]@{ original_ball = "T4"; substitute_ball = "P5"; bank_io_net = "BANK2_GPIO40" }
  76. PTC04 = [ordered]@{ original_ball = "R5"; substitute_ball = "T8"; bank_io_net = "BANK2_GPIO41" }
  77. PTC17 = [ordered]@{ original_ball = "P8"; substitute_ball = "M14"; bank_io_net = "BANK2_GPIO42" }
  78. PTC18 = [ordered]@{ original_ball = "P7"; substitute_ball = "M15"; bank_io_net = "BANK2_GPIO43" }
  79. PTC21 = [ordered]@{ original_ball = "P10"; substitute_ball = "P15"; bank_io_net = "BANK2_GPIO44" }
  80. PTC22 = [ordered]@{ original_ball = "R10"; substitute_ball = "N14"; bank_io_net = "BANK2_GPIO45" }
  81. }
  82. reserved_future_uart = $commonReservedFutureUart
  83. }
  84. }
  85. if ($SelectedProfile -eq "debug-photo-uart-bmc-replay") {
  86. return [ordered]@{
  87. name = "debug-photo-uart-bmc-replay"
  88. bmc_source = "pc_replay_from_real_bmc_capture"
  89. live_bmc_link_status = "not_used"
  90. hardware_access_status = "photo_visible_header"
  91. bmc_tx_ball = "T4"
  92. bmc_rx_ball = "R5"
  93. host_tx_ball = "P7"
  94. host_rx_ball = "P8"
  95. debug_rx_ball = "P10"
  96. debug_tx_ball = "R10"
  97. uart_assignments = [ordered]@{
  98. bmc_replay_uart_tx = [ordered]@{ fpga_ball = "T4"; role = "pc_replay_bmc_tx" }
  99. bmc_replay_uart_rx = [ordered]@{ fpga_ball = "R5"; role = "pc_replay_bmc_rx" }
  100. host_uart_tx = [ordered]@{ fpga_ball = "P7"; role = "host_control_tx" }
  101. host_uart_rx = [ordered]@{ fpga_ball = "P8"; role = "host_control_rx" }
  102. debug_uart_rx = [ordered]@{ fpga_ball = "P10"; role = "debug921_rx" }
  103. debug_uart_tx = [ordered]@{ fpga_ball = "R10"; role = "debug921_tx" }
  104. }
  105. ptc_substitutions = [ordered]@{
  106. PTC03 = [ordered]@{ original_ball = "T4"; substitute_ball = "P5"; bank_io_net = "BANK2_GPIO40"; reason = "photo_visible_uart_overlap_remap" }
  107. PTC04 = [ordered]@{ original_ball = "R5"; substitute_ball = "T8"; bank_io_net = "BANK2_GPIO41"; reason = "photo_visible_uart_overlap_remap" }
  108. PTC17 = [ordered]@{ original_ball = "P8"; substitute_ball = "M14"; bank_io_net = "BANK2_GPIO42"; reason = "photo_visible_uart_overlap_remap" }
  109. PTC18 = [ordered]@{ original_ball = "P7"; substitute_ball = "M15"; bank_io_net = "BANK2_GPIO43"; reason = "photo_visible_uart_overlap_remap" }
  110. PTC21 = [ordered]@{ original_ball = "P10"; substitute_ball = "P15"; bank_io_net = "BANK2_GPIO44"; reason = "photo_visible_uart_overlap_remap" }
  111. PTC22 = [ordered]@{ original_ball = "R10"; substitute_ball = "N14"; bank_io_net = "BANK2_GPIO45"; reason = "photo_visible_uart_overlap_remap" }
  112. }
  113. reserved_future_uart = $commonReservedFutureUart
  114. }
  115. }
  116. if ($SelectedProfile -eq "formal-uart1-bmc-replay") {
  117. return [ordered]@{
  118. name = "formal-uart1-bmc-replay"
  119. bmc_source = "pc_replay_from_real_bmc_capture"
  120. live_bmc_link_status = "not_used"
  121. hardware_access_status = "blocked_waiting_for_uart1_uart2_access"
  122. bmc_tx_ball = "L10"
  123. bmc_rx_ball = "M9"
  124. host_tx_ball = "M10"
  125. host_rx_ball = "N11"
  126. debug_rx_ball = "P15"
  127. debug_tx_ball = "N14"
  128. uart_assignments = [ordered]@{
  129. bmc_replay_uart_tx = [ordered]@{ fpga_ball = "L10"; role = "pc_replay_bmc_tx" }
  130. bmc_replay_uart_rx = [ordered]@{ fpga_ball = "M9"; role = "pc_replay_bmc_rx" }
  131. host_uart_tx = [ordered]@{ fpga_ball = "M10"; role = "host_control_tx" }
  132. host_uart_rx = [ordered]@{ fpga_ball = "N11"; role = "host_control_rx" }
  133. debug_uart_rx = [ordered]@{ fpga_ball = "P15"; role = "debug921_rx" }
  134. debug_uart_tx = [ordered]@{ fpga_ball = "N14"; role = "debug921_tx" }
  135. }
  136. ptc_substitutions = [ordered]@{}
  137. reserved_future_uart = $commonReservedFutureUart
  138. }
  139. }
  140. throw "Unsupported profile: $SelectedProfile"
  141. }
  142. function New-StartHereText([string]$SelectedProfile, [string]$BitName, [string]$TdName, [string]$ShortBit, [string]$ShortTd) {
  143. $pinMap = New-PinMap $SelectedProfile
  144. $isBmcReplay = $SelectedProfile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")
  145. $title = if ($isBmcReplay) { "J6 BMC replay Debug921 short-path package" } else { "J6 temp-uart-ptc-remap Debug921 v2 tailfix short-path package" }
  146. $ptcLine = if ($SelectedProfile -eq "formal-uart1-bmc-replay") {
  147. "- HEAT/PTC/FAN/FG/INSTALL use the PDF/inventory real schematic pins; no PTC substitution is active in this formal profile."
  148. } else {
  149. "- PTC03/PTC04/PTC17/PTC18/PTC21/PTC22 使用临时替代引脚;具体替代关系见 manifest.json。"
  150. }
  151. $wiring = @"
  152. - BMC UART:CPLD TX=$($pinMap.bmc_tx_ball),RX=$($pinMap.bmc_rx_ball)。
  153. - BMC source:pc_replay_from_real_bmc_capture,live_bmc_link_status=not_used。
  154. - DebugPort:COM7,CPLD RX=$($pinMap.debug_rx_ball),TX=$($pinMap.debug_tx_ball),921600 8N1。
  155. - HostPort:COM8,CPLD TX=$($pinMap.host_tx_ball),RX=$($pinMap.host_rx_ball),115200 8N1。
  156. - BmcReplayPort:COM9,115200 8N1,由 replay-bmc.ps1 只在看到 CPLD poll 后回复。
  157. $ptcLine
  158. - HostPort 上电后先输出 READY profile=temp-uart-ptc-remap seq=00000000。collector 会等待 HostPort READY 和 DebugPort J6READY 都出现,保存 startup-preflight.json,再进入严格 12 条正式命令序列。
  159. - collector_protocol_profile=temp-uart-ptc-remap:这是当前 RTL/collector 的 READY/J6READY 协议别名,不改变本包 pin_profile=$SelectedProfile。
  160. "@
  161. $hardwareNote = if ($SelectedProfile -eq "formal-uart1-bmc-replay") {
  162. "本 formal-uart1-bmc-replay profile 使用 UART1/UART2 预留引脚承载 PC BMC replay 与 HostPort,保留真实 PTC/FAN 映射;DebugPort 为 SPARE_GPIO44/45,TX=N14/RX=P15;hardware_access_status=blocked_waiting_for_uart1_uart2_access。"
  163. } elseif ($SelectedProfile -eq "debug-photo-uart-bmc-replay") {
  164. "本 debug-photo-uart-bmc-replay profile 保持照片可见调试串口接线,BMC 链路改为 PC replay,并把 6 路与串口冲突的 PTC 输出临时改到复核空闲 GPIO;hardware_access_status=photo_visible_header。"
  165. } else {
  166. "本 temp profile 保持当前三路调试串口接线不变,只把 6 路与串口冲突的 PTC 输出临时改到复核空闲 GPIO。"
  167. }
  168. return @"
  169. # $title
  170. ## 1. 先准备并启动 BMC replay
  171. BMC replay profiles use a PC replay source instead of a live BMC link. 先把真实 BMC 抓到的文本规范化成 payload,再在单独 PowerShell 窗口启动 replay-bmc.ps1。replay-bmc.ps1 会一直等待 CPLD 发出完整 poll,看到 poll 后才回复一帧历史 payload。
  172. capture-bmc.ps1 uses Python only to normalize a saved real-BMC text capture into the 48-byte replay payload. The package does not install Python/pip/driver and does not enumerate COM ports.
  173. ~~~powershell
  174. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\capture-bmc.ps1 -Input .\bmc-capture.txt -Payload .\bmc-replay-payload.json
  175. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\replay-bmc.ps1 -BmcReplayPort COM9 -Payload .\bmc-replay-payload.json
  176. ~~~
  177. 临时只想验证 CPLD poll/response 链路时,也可以先用包内 bmc-replay-payload.example.json:
  178. ~~~powershell
  179. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\replay-bmc.ps1 -BmcReplayPort COM9 -Payload .\bmc-replay-payload.example.json
  180. ~~~
  181. example payload 只能用于 debug fallback;严格 evidence 里 BMC source 仍应来自 `capture-bmc.ps1` 规范化的真实 BMC capture。
  182. 若 Windows 机器还没有 Python,请先由用户手动安装 Python;本包不会自动安装 Python/pip/driver。
  183. ## 2. 再启动 collector
  184. 确认 replay-bmc.ps1 已经在单独窗口等待后,在本包根目录打开另一个 PowerShell,复制执行下面这一条命令。collector 会先打开 COM8/COM7、等待 READY/J6READY,并把启动同步写入 startup-preflight.json。
  185. 端口参数:-HostPort COM8 -DebugPort COM7 -BmcReplayPort COM9
  186. ~~~powershell
  187. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collect.ps1 -HostPort COM8 -DebugPort COM7 -DurationSeconds 180 -OutputDir .\evidence-com8-host-com7-debug -Profile $SelectedProfile -Bitstream .\$ShortBit -TdReceipt .\$ShortTd
  188. ~~~
  189. 也可以执行包内快捷脚本:
  190. ~~~powershell
  191. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\commands\collect-template.ps1
  192. ~~~
  193. ## 3. collector 启动后手动刷 SRAM
  194. 刷 SRAM 前先确认板子外部电源已经接好,BitWriter/TD GUI 能识别 JTAG 链。现场有效设置是 JTAG speed 200k + board power present + PROGRAM_SRAM。
  195. 不要求重新上电;如果 JTAG/BitWriter 识别不到器件,第一检查项是板子电源是否接好,其次才是 JTAG 线束、AL-Link 和 speed 设置。
  196. collector 开始等待后,在 TD/ChipWatcher/BitWriter 中只执行 PROGRAM_SRAM,选择本包根目录下面这个短路径 bitstream:
  197. ~~~text
  198. .\$ShortBit
  199. ~~~
  200. 不要选择 bitstreams/$BitName 作为现场刷机主路径;那份长文件名副本只用于审计和 hash 对照。若 BitWriter 报 Cannot open file,第一检查项是是否误选了旧长包或 bitstreams 深目录里的长文件名 bitstream。
  201. 不要执行任何非易失存储写入、擦除或固化存储相关动作。
  202. collector first, then PROGRAM_SRAM. collector 会忽略 READY/J6READY 前的旧程序 ACK,并在未锁定新 SRAM epoch 时拒绝发送正式命令。
  203. ## 接线
  204. $wiring
  205. ## 采集内容
  206. - 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。
  207. - startup-preflight.json 记录 READY/J6READY epoch 锁定和 pre-SRAM noise;正式 transcript 必须仍然只有 12 条命令和 12 条匹配 ACK。
  208. - DebugPort 只读,预期证据帧包括 J6CMD/J6RAW/J6EVT/J6PWM/J6MOD/J6STAT/J6MAP/J6TEMP。
  209. - collector 结束前会执行 tail drain,等待 DebugPort 静默并记录最后 J6STAT 是否覆盖最后完整 J6RAW;若末尾只有不完整行,会记录到 manifest/debug-frame-stream,不会当作有效 replay 帧。
  210. - BMC 温度仍来自 J6 UART raw 命令,不使用 I2C、MCU、BMC_SCL/SDA 或 TEMP_SCL/SDA。
  211. ## 包内参考
  212. - [中文 runbook](docs/j6-host-sensor-real-fan-ptc-debug921-runbook.zh-CN.md)
  213. - [collector 脚本](collector/collect-j6-host-sensor-real-fan-ptc.ps1)
  214. - [SHA256 inventory](sha256-inventory.json)
  215. ## 边界
  216. $hardwareNote
  217. 本包只声明 SRAM-only 诊断链路、HostPort 控制、BMC raw 采样、温度解析和证据采集成立;不声明非易失存储写入、真实热性能、真实 PTC/FAN 负载或 PID 闭环通过。
  218. "@
  219. }
  220. function New-FormalBlockedText([string]$SelectedProfile) {
  221. $pinMap = New-PinMap $SelectedProfile
  222. return @"
  223. # J6 BMC replay formal-uart1 blocked package
  224. 本包不是可刷机包,不能刷机。
  225. ## 结论
  226. - status=blocked_td_mslice_over_limit
  227. - 最新 formal-uart1-bmc-replay P15/N14 DebugPort 尝试结果为 1137 mslices,器件限制为 1120 mslices。
  228. - 历史最佳 T8/P5 DebugPort 候选观察到 1131 mslices,仍超过 1120 限制。
  229. - 因此本轮没有生成 formal-uart1-bmc-replay SRAM bitstream,也没有短路径 bitstream 别名。
  230. - 不能把 debug-photo-uart-bmc-replay 的 bitstream 当作 formal 版使用,因为 debug-photo 版仍有 6 路 PTC remap,formal 版目标是全 HEAT/PTC/FAN 使用真实原理图引脚。
  231. ## formal 设计方向
  232. - BMC-Replay UART:CPLD TX=$($pinMap.bmc_tx_ball),RX=$($pinMap.bmc_rx_ball),PC 串口回放真实 BMC capture。
  233. - HostPort:CPLD TX=$($pinMap.host_tx_ball),RX=$($pinMap.host_rx_ball)。
  234. - DebugPort 候选:CPLD TX=$($pinMap.debug_tx_ball),RX=$($pinMap.debug_rx_ball)。这是 SPARE_GPIO44/45 候选,不占 HEAT/FAN/FG/INSTALL、UART1/2、时钟、复位或 LED。
  235. - HEAT1..24、FAN_PWM1..4、FAN_FG1..8、FAN_INSTALL1..4 保持 PDF/inventory 真实映射。
  236. ## 还需要什么才可发布 formal 可刷包
  237. 1. 先做 debug921 RTL 资源削减或 TD packing 策略实验,至少减少 11 个 mslices,并保留 UART/Host/BMC replay/Debug evidence 行为。
  238. 2. 重新跑 TD build,必须实际生成 formal `.bit`。
  239. 3. 重新跑 package/selftest/hash/safety scan。
  240. 4. UART1/2 与 DebugPort 候选脚还需要现场连通性或可接线复核;在复核前 hardware_access_status 仍为 blocked_waiting_for_uart1_uart2_access。
  241. ## 边界
  242. - BMC source=pc_replay_from_real_bmc_capture,不声明 live_bmc_pass。
  243. - real_fan_ptc_hardware_status=not_run。
  244. - 不声明 flash、真实热性能、真实 PID 闭环或真实 PTC/FAN 负载通过。
  245. 包内 `td.json` 是 TD 失败 receipt,`manifest.json` 是本 blocked 包的机器可读说明。
  246. "@
  247. }
  248. $repoRoot = Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..")
  249. $out = (Resolve-Path -LiteralPath (New-Item -ItemType Directory -Force -Path $OutputDir)).Path
  250. if ($FormalBlocked -and $Profile -ne "formal-uart1-bmc-replay") {
  251. throw "-FormalBlocked is only valid with -Profile formal-uart1-bmc-replay."
  252. }
  253. if (-not $FormalBlocked -and [string]::IsNullOrWhiteSpace($Bitstream)) {
  254. throw "-Bitstream is required unless -FormalBlocked is specified."
  255. }
  256. if ([string]::IsNullOrWhiteSpace($PackageName)) {
  257. $stamp = Get-Date -Format "yyyyMMdd-HHmmss"
  258. $PackageName = "j6tmp-v2-tailfix-$stamp"
  259. }
  260. $stage = Join-Path $out $PackageName
  261. if (Test-Path -LiteralPath $stage) {
  262. if (-not $ForceOverwrite) {
  263. throw "Package staging directory already exists: $stage. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
  264. }
  265. $resolvedStage = (Resolve-Path -LiteralPath $stage).Path
  266. $resolvedOut = (Resolve-Path -LiteralPath $out).Path.TrimEnd('\')
  267. if (-not $resolvedStage.StartsWith($resolvedOut, [System.StringComparison]::OrdinalIgnoreCase)) {
  268. throw "Refusing to remove package directory outside output dir: $resolvedStage"
  269. }
  270. Remove-Item -LiteralPath $resolvedStage -Recurse -Force
  271. }
  272. foreach ($dir in @("bitstreams", "td-receipts", "collector", "commands", "schemas", "docs", "config", "bmc-replay")) {
  273. New-Item -ItemType Directory -Force -Path (Join-Path $stage $dir) | Out-Null
  274. }
  275. $collectorPath = Join-Path $repoRoot "tools\remote\collect-j6-host-sensor-real-fan-ptc.ps1"
  276. $bmcReplayPath = Join-Path $repoRoot "tools\bmc_replay_uart.py"
  277. $schemaPath = Join-Path $repoRoot "schemas\real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt.schema.json"
  278. $runbookPath = Join-Path $repoRoot "docs\j6-host-sensor-real-fan-ptc-debug921-runbook.zh-CN.md"
  279. $pinInventoryPath = Join-Path $repoRoot "config\pin_inventory.fcb_fpga_mcu0611.json"
  280. if ($FormalBlocked) {
  281. $tdReceiptCopy = Copy-IntoPackage $TdReceipt (Join-Path $stage "td-receipts")
  282. Copy-IntoPackage $schemaPath (Join-Path $stage "schemas") | Out-Null
  283. Copy-IntoPackage $runbookPath (Join-Path $stage "docs") | Out-Null
  284. Copy-IntoPackage $pinInventoryPath (Join-Path $stage "config") | Out-Null
  285. Copy-Item -LiteralPath $tdReceiptCopy -Destination (Join-Path $stage $ShortTdName) -Force
  286. Set-Content -LiteralPath (Join-Path $stage "START-HERE.zh-CN.md") -Encoding UTF8 -Value (New-FormalBlockedText $Profile)
  287. Set-Content -LiteralPath (Join-Path $stage "FORMAL-BLOCKED.zh-CN.md") -Encoding UTF8 -Value (New-FormalBlockedText $Profile)
  288. $pinMap = New-PinMap $Profile
  289. $manifest = [ordered]@{
  290. schema = "j6-host-sensor-real-fan-ptc-debug921-package-manifest-v1"
  291. status = "blocked_td_mslice_over_limit"
  292. generated_at = (Get-Date).ToUniversalTime().ToString("o")
  293. package_name = $PackageName
  294. diagnostic_scope = "host_sensor_real_fan_ptc_debug921"
  295. pin_profile = $Profile
  296. programming_mode = "not_available"
  297. bitstream = $null
  298. td_receipt = [ordered]@{ path = $ShortTdName; sha256 = Get-Sha256 (Join-Path $stage $ShortTdName) }
  299. blocked_reason = [ordered]@{
  300. code = "blocked_td_mslice_over_limit"
  301. latest_attempt_mslices = 1137
  302. latest_attempt_debug_uart_rx_ball = "P15"
  303. latest_attempt_debug_uart_tx_ball = "N14"
  304. best_observed_mslices = 1131
  305. best_observed_debug_uart_rx_ball = "T8"
  306. best_observed_debug_uart_tx_ball = "P5"
  307. device_mslice_limit = 1120
  308. no_flashable_formal_bitstream = $true
  309. }
  310. bmc_source = "pc_replay_from_real_bmc_capture"
  311. live_bmc_link_status = "not_used"
  312. pin_map = $pinMap
  313. real_fan_ptc_hardware_status = "not_run"
  314. remote_dependencies = "None for this blocked package."
  315. authority_boundary = "Blocked formal package. It records TD failure evidence only and must not be used for device programming."
  316. }
  317. $manifest | ConvertTo-Json -Depth 64 | Set-Content -LiteralPath (Join-Path $stage "manifest.json") -Encoding UTF8
  318. $inventory = New-Object System.Collections.Generic.List[object]
  319. Get-ChildItem -LiteralPath $stage -Recurse -File | Sort-Object FullName | ForEach-Object {
  320. if ($_.Name -eq "sha256-inventory.json") {
  321. return
  322. }
  323. $inventory.Add((New-InventoryItem $_.FullName $stage)) | Out-Null
  324. }
  325. [ordered]@{
  326. schema = "j6-host-sensor-real-fan-ptc-debug921-package-sha256-inventory-v1"
  327. generated_at = (Get-Date).ToUniversalTime().ToString("o")
  328. self_hash_policy = "excluded_self_referential_file"
  329. inventory = $inventory
  330. } | ConvertTo-Json -Depth 32 | Set-Content -LiteralPath (Join-Path $stage "sha256-inventory.json") -Encoding UTF8
  331. $zipPath = Join-Path $out ($PackageName + ".zip")
  332. if (Test-Path -LiteralPath $zipPath) {
  333. if (-not $ForceOverwrite) {
  334. throw "Package zip already exists: $zipPath. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
  335. }
  336. Remove-Item -LiteralPath $zipPath -Force
  337. }
  338. $zipSidecar = $zipPath + ".sha256.txt"
  339. if (Test-Path -LiteralPath $zipSidecar) {
  340. if (-not $ForceOverwrite) {
  341. throw "Package zip sidecar already exists: $zipSidecar. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
  342. }
  343. Remove-Item -LiteralPath $zipSidecar -Force
  344. }
  345. Compress-Archive -Path (Join-Path $stage "*") -DestinationPath $zipPath -Force
  346. $zipSha = Get-Sha256 $zipPath
  347. Set-Content -LiteralPath $zipSidecar -Encoding ASCII -Value ("{0} {1}" -f $zipSha, (Split-Path -Leaf $zipPath))
  348. Write-Host "Wrote $stage"
  349. Write-Host "Wrote $zipPath"
  350. Write-Host ("SHA256 {0} {1}" -f $zipSha, $zipPath)
  351. exit 0
  352. }
  353. $bitstreamCopy = Copy-IntoPackage $Bitstream (Join-Path $stage "bitstreams")
  354. $tdReceiptCopy = Copy-IntoPackage $TdReceipt (Join-Path $stage "td-receipts")
  355. Copy-IntoPackage $collectorPath (Join-Path $stage "collector") | Out-Null
  356. Copy-IntoPackage $bmcReplayPath (Join-Path $stage "bmc-replay") | Out-Null
  357. Copy-IntoPackage $schemaPath (Join-Path $stage "schemas") | Out-Null
  358. Copy-IntoPackage $runbookPath (Join-Path $stage "docs") | Out-Null
  359. Copy-IntoPackage $pinInventoryPath (Join-Path $stage "config") | Out-Null
  360. $bitName = Split-Path -Leaf $bitstreamCopy
  361. $tdName = Split-Path -Leaf $tdReceiptCopy
  362. Copy-Item -LiteralPath $bitstreamCopy -Destination (Join-Path $stage $ShortBitName) -Force
  363. Copy-Item -LiteralPath $tdReceiptCopy -Destination (Join-Path $stage $ShortTdName) -Force
  364. $shortcut = @'
  365. param(
  366. [string]$HostPort = "",
  367. [string]$DebugPort = "",
  368. [int]$DurationSeconds = 180,
  369. [string]$OutputDir = ".\evidence-com8-host-com7-debug",
  370. [ValidateSet("temp-uart-ptc-remap", "debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")]
  371. [string]$Profile = "temp-uart-ptc-remap",
  372. [string]$Bitstream = ".\j6tmp.bit",
  373. [string]$TdReceipt = ".\td.json",
  374. [int]$JtagSpeedHz = 200000,
  375. [object]$BoardPowerPresentBeforeProgram = $true,
  376. [switch]$SelfTest
  377. )
  378. $ErrorActionPreference = "Stop"
  379. $packageRoot = $PSScriptRoot
  380. $collector = Join-Path $packageRoot "collector\collect-j6-host-sensor-real-fan-ptc.ps1"
  381. $bitstreamPath = if ([System.IO.Path]::IsPathRooted($Bitstream)) { $Bitstream } else { Join-Path $packageRoot $Bitstream }
  382. $tdReceiptPath = if ([System.IO.Path]::IsPathRooted($TdReceipt)) { $TdReceipt } else { Join-Path $packageRoot $TdReceipt }
  383. $collectorProfile = if ($Profile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")) { "temp-uart-ptc-remap" } else { $Profile }
  384. $argsList = @(
  385. "-NoProfile",
  386. "-ExecutionPolicy", "Bypass",
  387. "-File", $collector
  388. )
  389. if ($SelfTest) {
  390. $argsList += "-SelfTest"
  391. } else {
  392. $argsList += @(
  393. "-HostPort", $HostPort,
  394. "-DebugPort", $DebugPort,
  395. "-DurationSeconds", $DurationSeconds,
  396. "-OutputDir", $OutputDir,
  397. "-Profile", $collectorProfile,
  398. "-Bitstream", $bitstreamPath,
  399. "-TdReceipt", $tdReceiptPath,
  400. "-JtagSpeedHz", $JtagSpeedHz,
  401. "-BoardPowerPresentBeforeProgram", $BoardPowerPresentBeforeProgram
  402. )
  403. }
  404. & "$PSHOME\powershell.exe" @argsList
  405. if ($LASTEXITCODE -ne 0) {
  406. exit $LASTEXITCODE
  407. }
  408. '@
  409. Set-Content -LiteralPath (Join-Path $stage "collect.ps1") -Encoding UTF8 -Value $shortcut
  410. $captureBmc = @'
  411. param(
  412. [ValidatePattern('^COM[0-9]+$')]
  413. [string]$BmcCapturePort = "",
  414. [string]$Input = ".\bmc-capture.txt",
  415. [string]$Payload = ".\bmc-replay-payload.json",
  416. [int]$Seq = 1,
  417. [int]$TimeoutSeconds = 3
  418. )
  419. $ErrorActionPreference = "Stop"
  420. $packageRoot = $PSScriptRoot
  421. $helper = Join-Path $packageRoot "bmc-replay\bmc_replay_uart.py"
  422. $inputPath = if ([System.IO.Path]::IsPathRooted($Input)) { $Input } else { Join-Path $packageRoot $Input }
  423. $payloadPath = if ([System.IO.Path]::IsPathRooted($Payload)) { $Payload } else { Join-Path $packageRoot $Payload }
  424. if (-not [string]::IsNullOrWhiteSpace($BmcCapturePort)) {
  425. $serial = New-Object System.IO.Ports.SerialPort
  426. $serial.PortName = $BmcCapturePort
  427. $serial.BaudRate = 115200
  428. $serial.DataBits = 8
  429. $serial.Parity = [System.IO.Ports.Parity]::None
  430. $serial.StopBits = [System.IO.Ports.StopBits]::One
  431. $serial.Handshake = [System.IO.Ports.Handshake]::None
  432. $serial.DtrEnable = $false
  433. $serial.RtsEnable = $false
  434. $serial.ReadTimeout = 50
  435. $serial.WriteTimeout = 1000
  436. $rawCommand = "ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03`n"
  437. $chunks = New-Object System.Collections.Generic.List[byte]
  438. try {
  439. $serial.Open()
  440. $bytes = [System.Text.Encoding]::ASCII.GetBytes($rawCommand)
  441. $serial.Write($bytes, 0, $bytes.Length)
  442. $deadline = (Get-Date).ToUniversalTime().AddSeconds($TimeoutSeconds)
  443. while ((Get-Date).ToUniversalTime() -lt $deadline) {
  444. try {
  445. $value = $serial.ReadByte()
  446. if ($value -ge 0) {
  447. $chunks.Add([byte]$value) | Out-Null
  448. }
  449. } catch [System.TimeoutException] {
  450. Start-Sleep -Milliseconds 10
  451. }
  452. }
  453. } finally {
  454. if ($serial.IsOpen) {
  455. $serial.Close()
  456. }
  457. }
  458. $text = [System.Text.Encoding]::ASCII.GetString($chunks.ToArray())
  459. if ([string]::IsNullOrWhiteSpace($text)) {
  460. throw "No BMC capture text received from $BmcCapturePort"
  461. }
  462. Set-Content -LiteralPath $inputPath -Encoding ASCII -Value $text
  463. }
  464. & python $helper normalize-capture --input $inputPath --payload $payloadPath --seq $Seq --json
  465. if ($LASTEXITCODE -ne 0) {
  466. exit $LASTEXITCODE
  467. }
  468. '@
  469. Set-Content -LiteralPath (Join-Path $stage "capture-bmc.ps1") -Encoding UTF8 -Value $captureBmc
  470. $examplePayload = [ordered]@{
  471. schema = "j6-bmc-replay-payload-v1"
  472. status = "debug_example_only"
  473. source = "synthetic_example"
  474. bmc_source = "example_payload_not_real_bmc_capture"
  475. live_bmc_link_status = "not_used"
  476. replay_mode = "poll_response"
  477. seq = 0
  478. poll_text = "ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03"
  479. poll_command_text = "ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03`n"
  480. reply_text = "28 00 29 00 2a 00 2b 00 2c 00 2d 00 2e 00 2f 00 30 00 31 00 32 00 33 00 34 00 35 00 36 00 37 00 38 00 39 00 3a 00 3b 00 3c 00 3d 00 3e 00 3f 00`r`n"
  481. reply_sha256 = ""
  482. byte_count = 48
  483. valid_count = 24
  484. missing_count = 0
  485. safety = [ordered]@{
  486. unsolicited_reply_attempted = $false
  487. driver_install_attempted = $false
  488. programs_nonvolatile = $false
  489. }
  490. authority_boundary = "Synthetic example payload for temporary BMC replay wiring debug only. It is not real BMC evidence."
  491. }
  492. $examplePayload.reply_sha256 = Get-StringSha256 $examplePayload.reply_text
  493. $examplePayload | ConvertTo-Json -Depth 16 | Set-Content -LiteralPath (Join-Path $stage "bmc-replay-payload.example.json") -Encoding UTF8
  494. $replayBmc = @'
  495. param(
  496. [ValidatePattern('^COM[0-9]+$')]
  497. [string]$BmcReplayPort = "COM9",
  498. [string]$Payload = ".\bmc-replay-payload.json",
  499. [int]$Iterations = 0,
  500. [int]$TimeoutSeconds = 0,
  501. [switch]$SelfTest
  502. )
  503. $ErrorActionPreference = "Stop"
  504. $packageRoot = $PSScriptRoot
  505. $payloadPath = if ([System.IO.Path]::IsPathRooted($Payload)) { $Payload } else { Join-Path $packageRoot $Payload }
  506. function Read-Payload([string]$Path) {
  507. if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
  508. throw "Payload file not found: $Path"
  509. }
  510. $payload = Get-Content -LiteralPath $Path -Raw | ConvertFrom-Json
  511. if ([string]::IsNullOrWhiteSpace([string]$payload.reply_text)) {
  512. throw "Payload missing reply_text"
  513. }
  514. $pollText = [string]$payload.poll_command_text
  515. if ([string]::IsNullOrWhiteSpace($pollText)) {
  516. $pollText = [string]$payload.poll_text
  517. if (-not $pollText.EndsWith("`n")) {
  518. $pollText = $pollText + "`n"
  519. }
  520. }
  521. return [ordered]@{
  522. poll = $pollText
  523. reply = [string]$payload.reply_text
  524. sha256 = [string]$payload.reply_sha256
  525. }
  526. }
  527. function Invoke-ReplayCore($Endpoint, [string]$PollText, [string]$ReplyText, [int]$MaxIterations, [int]$MaxSeconds) {
  528. $poll = [System.Text.Encoding]::ASCII.GetBytes($PollText)
  529. $reply = [System.Text.Encoding]::ASCII.GetBytes($ReplyText)
  530. $window = New-Object System.Collections.Generic.List[byte]
  531. $matched = 0
  532. $deadline = if ($MaxSeconds -gt 0) { (Get-Date).ToUniversalTime().AddSeconds($MaxSeconds) } else { [DateTime]::MaxValue }
  533. while ($matched -lt $MaxIterations -or $MaxIterations -eq 0) {
  534. if ((Get-Date).ToUniversalTime() -gt $deadline) {
  535. break
  536. }
  537. $value = $Endpoint.ReadByte()
  538. if ($value -lt 0) {
  539. Start-Sleep -Milliseconds 2
  540. continue
  541. }
  542. $window.Add([byte]$value) | Out-Null
  543. $limit = [Math]::Max(4096, $poll.Length * 2)
  544. while ($window.Count -gt $limit) {
  545. $window.RemoveAt(0)
  546. }
  547. if ($window.Count -ge $poll.Length) {
  548. $match = $true
  549. for ($i = 0; $i -lt $poll.Length; $i++) {
  550. if ($window[$window.Count - $poll.Length + $i] -ne $poll[$i]) {
  551. $match = $false
  552. break
  553. }
  554. }
  555. if ($match) {
  556. $Endpoint.Write($reply, 0, $reply.Length)
  557. $matched += 1
  558. $window.Clear()
  559. Write-Host ("replay_reply_count={0}" -f $matched)
  560. }
  561. }
  562. }
  563. return [ordered]@{
  564. status = if ($matched -gt 0) { "pass" } else { "blocked_waiting_for_cpld_poll" }
  565. matched_poll_count = $matched
  566. reply_count = $matched
  567. unsolicited_reply_attempted = $false
  568. }
  569. }
  570. if ($SelfTest) {
  571. $tmp = Join-Path $env:TEMP ("j6-bmc-replay-selftest-" + [Guid]::NewGuid().ToString("N") + ".json")
  572. try {
  573. $sample = [ordered]@{
  574. reply_text = "28 00 29 00 2a 00 2b 00 2c 00 2d 00 2e 00 2f 00 30 00 31 00 32 00 33 00 34 00 35 00 36 00 37 00 38 00 39 00 3a 00 3b 00 3c 00 3d 00 3e 00 3f 00`r`n"
  575. reply_sha256 = ""
  576. poll_command_text = "ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03`n"
  577. }
  578. $sample | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $tmp -Encoding UTF8
  579. $p = Read-Payload $tmp
  580. if (-not $p.poll.Contains("ipmitool raw")) { throw "poll selftest failed" }
  581. if (-not $p.reply.EndsWith("`n")) { throw "reply selftest failed" }
  582. Write-Host "selftest=pass"
  583. exit 0
  584. } finally {
  585. if (Test-Path -LiteralPath $tmp) {
  586. Remove-Item -LiteralPath $tmp -Force
  587. }
  588. }
  589. }
  590. $replayPayload = Read-Payload $payloadPath
  591. $serial = New-Object System.IO.Ports.SerialPort
  592. $serial.PortName = $BmcReplayPort
  593. $serial.BaudRate = 115200
  594. $serial.DataBits = 8
  595. $serial.Parity = [System.IO.Ports.Parity]::None
  596. $serial.StopBits = [System.IO.Ports.StopBits]::One
  597. $serial.Handshake = [System.IO.Ports.Handshake]::None
  598. $serial.DtrEnable = $false
  599. $serial.RtsEnable = $false
  600. $serial.ReadTimeout = 25
  601. $serial.WriteTimeout = 1000
  602. try {
  603. $serial.Open()
  604. Write-Host "Ready to replay BMC payload on $BmcReplayPort from $payloadPath"
  605. Write-Host "Safety: reply only after CPLD poll; no dependency setup, no COM enumeration, no device programming."
  606. $receipt = Invoke-ReplayCore $serial $replayPayload.poll $replayPayload.reply $Iterations $TimeoutSeconds
  607. $receipt | ConvertTo-Json -Depth 8
  608. } finally {
  609. if ($serial.IsOpen) {
  610. $serial.Close()
  611. }
  612. }
  613. '@
  614. Set-Content -LiteralPath (Join-Path $stage "replay-bmc.ps1") -Encoding UTF8 -Value $replayBmc
  615. $template = @'
  616. & "$PSHOME\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File .\collect.ps1 -HostPort COM8 -DebugPort COM7 -DurationSeconds 180 -OutputDir .\evidence-com8-host-com7-debug -Profile __PROFILE__ -Bitstream .\j6tmp.bit -TdReceipt .\td.json
  617. '@
  618. $template = $template.Replace("__PROFILE__", $Profile)
  619. Set-Content -LiteralPath (Join-Path $stage "commands\collect-template.ps1") -Encoding UTF8 -Value $template
  620. Set-Content -LiteralPath (Join-Path $stage "START-HERE.zh-CN.md") -Encoding UTF8 -Value (New-StartHereText $Profile $bitName $tdName $ShortBitName $ShortTdName)
  621. $hostControlCommands = @(
  622. "SET PTC 01 10",
  623. "SET PTC 24 20",
  624. "SET FAN 01 40",
  625. "SET FAN 04 30",
  626. "SET PID ENABLE",
  627. "GET STATUS",
  628. "GET MAP",
  629. "GET SENSOR",
  630. "GET SENSOR",
  631. "GET SENSOR",
  632. "SET PID DISABLE",
  633. "DISABLE"
  634. )
  635. $pinMap = New-PinMap $Profile
  636. $manifest = [ordered]@{
  637. schema = "j6-host-sensor-real-fan-ptc-debug921-package-manifest-v1"
  638. status = "pass"
  639. generated_at = (Get-Date).ToUniversalTime().ToString("o")
  640. package_name = $PackageName
  641. diagnostic_scope = "host_sensor_real_fan_ptc_debug921"
  642. pin_profile = $Profile
  643. programming_mode = "PROGRAM_SRAM"
  644. jtag_programming = [ordered]@{
  645. program_mode = "PROGRAM_SRAM"
  646. jtag_speed_hz = 200000
  647. board_power_present_before_program = $true
  648. tooling = "manual BitWriter/TD GUI"
  649. cli_programming_supported = $false
  650. cli_speed_mapping_proven = $false
  651. }
  652. bitstream = [ordered]@{ path = $ShortBitName; sha256 = Get-Sha256 (Join-Path $stage $ShortBitName) }
  653. td_receipt = [ordered]@{ path = $ShortTdName; sha256 = Get-Sha256 (Join-Path $stage $ShortTdName) }
  654. short_path_aliases = [ordered]@{
  655. bitstream = [ordered]@{
  656. path = $ShortBitName
  657. source = "bitstreams/$bitName"
  658. sha256 = Get-Sha256 (Join-Path $stage $ShortBitName)
  659. }
  660. td_receipt = [ordered]@{
  661. path = $ShortTdName
  662. source = "td-receipts/$tdName"
  663. sha256 = Get-Sha256 (Join-Path $stage $ShortTdName)
  664. }
  665. }
  666. collector = [ordered]@{
  667. path = "collector/collect-j6-host-sensor-real-fan-ptc.ps1"
  668. shortcut = "collect.ps1"
  669. user_profile_argument = $Profile
  670. profile_argument = $Profile
  671. collector_protocol_profile = if ($Profile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")) { "temp-uart-ptc-remap" } else { $Profile }
  672. ready_profile_string = "temp-uart-ptc-remap"
  673. }
  674. bmc_source = if ($Profile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")) { "pc_replay_from_real_bmc_capture" } else { "live_bmc_uart" }
  675. live_bmc_link_status = if ($Profile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")) { "not_used" } else { "used" }
  676. bmc_replay = [ordered]@{
  677. helper = "bmc-replay/bmc_replay_uart.py"
  678. capture_shortcut = "capture-bmc.ps1"
  679. replay_shortcut = "replay-bmc.ps1"
  680. example_payload = "bmc-replay-payload.example.json"
  681. strict_payload_source = "capture-bmc.ps1 normalized real BMC capture"
  682. example_payload_authority = "debug fallback only; not real BMC evidence"
  683. port_argument = "BmcReplayPort"
  684. default_port = "COM9"
  685. mode = "pc_replay_from_real_bmc_capture"
  686. unsolicited_reply_attempted = $false
  687. }
  688. host_control_commands = $hostControlCommands
  689. startup_preflight = [ordered]@{
  690. expected_artifact = "startup-preflight.json"
  691. ready_line = "READY profile=temp-uart-ptc-remap seq=00000000"
  692. j6ready_line = "J6READY profile=temp-uart-ptc-remap"
  693. epoch_locked_required = $true
  694. formal_ack_count = 12
  695. }
  696. tail_drain = [ordered]@{
  697. expected_manifest_field = "debug_tail"
  698. expected_stream_field = "tail"
  699. purpose = "Close the DebugPort capture window so post-J6STAT complete J6RAW tail is attributed instead of misreported as frame loss."
  700. }
  701. pin_map = $pinMap
  702. real_fan_ptc_hardware_status = "not_run"
  703. remote_dependencies = if ($Profile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")) { "PowerShell, .NET SerialPort, and user-provided Python for capture-bmc.ps1 normalization only; no pip setup, no driver setup, no COM enumeration." } else { "PowerShell and .NET SerialPort only; no remote dependency setup." }
  704. 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."
  705. authority_boundary = "SRAM-only diagnostic package. It does not program nonvolatile memory, change drivers, enumerate unknown COM ports, write DebugPort, claim thermal performance, or claim PID closed-loop pass."
  706. }
  707. $manifestPath = Join-Path $stage "manifest.json"
  708. $manifest | ConvertTo-Json -Depth 64 | Set-Content -LiteralPath $manifestPath -Encoding UTF8
  709. $inventory = New-Object System.Collections.Generic.List[object]
  710. Get-ChildItem -LiteralPath $stage -Recurse -File | Sort-Object FullName | ForEach-Object {
  711. if ($_.Name -eq "sha256-inventory.json") {
  712. return
  713. }
  714. $inventory.Add((New-InventoryItem $_.FullName $stage)) | Out-Null
  715. }
  716. [ordered]@{
  717. schema = "j6-host-sensor-real-fan-ptc-debug921-package-sha256-inventory-v1"
  718. generated_at = (Get-Date).ToUniversalTime().ToString("o")
  719. self_hash_policy = "excluded_self_referential_file"
  720. inventory = $inventory
  721. } | ConvertTo-Json -Depth 32 | Set-Content -LiteralPath (Join-Path $stage "sha256-inventory.json") -Encoding UTF8
  722. $zipPath = Join-Path $out ($PackageName + ".zip")
  723. if (Test-Path -LiteralPath $zipPath) {
  724. if (-not $ForceOverwrite) {
  725. throw "Package zip already exists: $zipPath. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
  726. }
  727. Remove-Item -LiteralPath $zipPath -Force
  728. }
  729. $zipSidecar = $zipPath + ".sha256.txt"
  730. if (Test-Path -LiteralPath $zipSidecar) {
  731. if (-not $ForceOverwrite) {
  732. throw "Package zip sidecar already exists: $zipSidecar. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
  733. }
  734. Remove-Item -LiteralPath $zipSidecar -Force
  735. }
  736. Compress-Archive -Path (Join-Path $stage "*") -DestinationPath $zipPath -Force
  737. $zipSha = Get-Sha256 $zipPath
  738. Set-Content -LiteralPath $zipSidecar -Encoding ASCII -Value ("{0} {1}" -f $zipSha, (Split-Path -Leaf $zipPath))
  739. Write-Host "Wrote $stage"
  740. Write-Host "Wrote $zipPath"
  741. Write-Host ("SHA256 {0} {1}" -f $zipSha, $zipPath)