package_j6_binary921.ps1 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. param(
  2. [string]$OutputDir = ".\j6-binary921-deliverables",
  3. [string]$PackageName = "",
  4. [Parameter(Mandatory = $true)]
  5. [ValidateSet("debug-photo-bmc-replay-binary921", "formal-uart1-bmc-replay-binary921", "production-two-uart-bmc-replay-binary921")]
  6. [string]$Profile,
  7. [Parameter(Mandatory = $true)]
  8. [string]$Bitstream,
  9. [Parameter(Mandatory = $true)]
  10. [string]$TdReceipt,
  11. [string]$BmcReplayPayload = "",
  12. [switch]$ForceOverwrite
  13. )
  14. $ErrorActionPreference = "Stop"
  15. $ShortBitName = "j6bin.bit"
  16. $ShortTdName = "td.json"
  17. function Get-Sha256([string]$Path) {
  18. if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
  19. throw "File not found: $Path"
  20. }
  21. return (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant()
  22. }
  23. function Test-Sha256String([object]$Value) {
  24. if ($null -eq $Value) { return $false }
  25. return ([string]$Value) -match '^[0-9a-fA-F]{64}$'
  26. }
  27. function Get-AsciiSha256([string]$Text) {
  28. $bytes = [System.Text.Encoding]::ASCII.GetBytes($Text)
  29. $sha = [System.Security.Cryptography.SHA256]::Create()
  30. try {
  31. return (($sha.ComputeHash($bytes) | ForEach-Object { $_.ToString("x2") }) -join "")
  32. } finally {
  33. $sha.Dispose()
  34. }
  35. }
  36. function Read-JsonFile([string]$Path, [string]$Label) {
  37. try {
  38. return Get-Content -LiteralPath $Path -Raw -Encoding UTF8 | ConvertFrom-Json
  39. } catch {
  40. throw "$Label is not valid JSON: $Path"
  41. }
  42. }
  43. function Assert-ProductionTdReceipt([string]$ReceiptPath, [string]$BitstreamPath, [string]$SelectedProfile) {
  44. $receipt = Read-JsonFile $ReceiptPath "TD receipt"
  45. $expectedTop = "uart_rs232_j6_host_sensor_real_fan_ptc_production_two_uart_bmc_replay_binary921"
  46. $expectedModule = "${expectedTop}_top"
  47. if ($receipt.status -ne "pass") { throw "TD receipt status must be pass for production package" }
  48. if ($receipt.top -ne $expectedTop) { throw "TD receipt top mismatch for production package" }
  49. if ($receipt.top_module -ne $expectedModule) { throw "TD receipt top_module mismatch for production package" }
  50. if ($receipt.pin_profile -ne $SelectedProfile) { throw "TD receipt pin_profile mismatch for production package" }
  51. if ($receipt.mode -ne "implementation") { throw "TD receipt mode must be implementation for production package" }
  52. if ($receipt.timing_gate.status -ne "pass") { throw "TD receipt timing_gate.status must be pass for production package" }
  53. $receiptBitSha = [string]$receipt.bitstream.sha256
  54. if (-not (Test-Sha256String $receiptBitSha)) { throw "TD receipt bitstream.sha256 missing or invalid for production package" }
  55. $actualBitSha = Get-Sha256 $BitstreamPath
  56. if ($receiptBitSha.ToLowerInvariant() -ne $actualBitSha) {
  57. throw "TD receipt bitstream.sha256 does not match provided bitstream"
  58. }
  59. return $receipt
  60. }
  61. function Assert-ProductionBmcPayload([string]$PayloadPath) {
  62. $payload = Read-JsonFile $PayloadPath "BMC replay payload"
  63. if ($payload.status -ne "pass") { throw "BMC replay payload status must be pass" }
  64. if ($payload.source -ne "real_bmc_capture") { throw "BMC replay payload source must be real_bmc_capture" }
  65. if ($payload.bmc_source -ne "pc_replay_from_real_bmc_capture") { throw "BMC replay payload bmc_source mismatch" }
  66. if ([int]$payload.byte_count -ne 48) { throw "BMC replay payload byte_count must be 48" }
  67. if ([int]$payload.valid_count -ne 2 -or [int]$payload.missing_count -ne 22) {
  68. throw "BMC replay payload for this production package must be the historical 2-valid/22-missing sample"
  69. }
  70. $replySha = [string]$payload.reply_sha256
  71. if (-not (Test-Sha256String $replySha)) { throw "BMC replay payload reply_sha256 missing or invalid" }
  72. $expectedHistoricalSha = "06c173f91f8b6b0e56f9c381b49d5b127d2dbf3a09402843838a0ff2b812f1af"
  73. if ($replySha.ToLowerInvariant() -ne $expectedHistoricalSha) {
  74. throw "BMC replay payload reply_sha256 must match the locked historical production sample"
  75. }
  76. $replyText = [string]$payload.reply_text
  77. if ([string]::IsNullOrWhiteSpace($replyText)) { throw "BMC replay payload reply_text missing" }
  78. $actualReplySha = Get-AsciiSha256 $replyText
  79. if ($actualReplySha -ne $replySha.ToLowerInvariant()) {
  80. throw "BMC replay payload reply_sha256 does not match reply_text"
  81. }
  82. if (-not (Test-Sha256String $payload.capture_text_sha256)) {
  83. throw "BMC replay payload capture_text_sha256 missing or invalid"
  84. }
  85. return $payload
  86. }
  87. function New-InventoryItem([string]$Path, [string]$Root) {
  88. $full = (Resolve-Path -LiteralPath $Path).Path
  89. $base = (Resolve-Path -LiteralPath $Root).Path.TrimEnd('\')
  90. $relative = $full.Substring($base.Length).TrimStart('\').Replace('\', '/')
  91. return [ordered]@{
  92. path = $relative
  93. sha256 = Get-Sha256 $full
  94. bytes = (Get-Item -LiteralPath $full).Length
  95. }
  96. }
  97. function Copy-IntoPackage([string]$Source, [string]$DestinationDir, [string]$DestinationName = "") {
  98. if (-not (Test-Path -LiteralPath $Source -PathType Leaf)) {
  99. throw "File not found: $Source"
  100. }
  101. New-Item -ItemType Directory -Force -Path $DestinationDir | Out-Null
  102. $name = if ([string]::IsNullOrWhiteSpace($DestinationName)) { Split-Path -Leaf $Source } else { $DestinationName }
  103. $destination = Join-Path $DestinationDir $name
  104. Copy-Item -LiteralPath $Source -Destination $destination -Force
  105. return $destination
  106. }
  107. function Remove-PythonCache([string]$Root) {
  108. if (-not (Test-Path -LiteralPath $Root -PathType Container)) { return }
  109. Get-ChildItem -LiteralPath $Root -Recurse -Force -Directory -Filter "__pycache__" | ForEach-Object {
  110. Remove-Item -LiteralPath $_.FullName -Recurse -Force
  111. }
  112. Get-ChildItem -LiteralPath $Root -Recurse -Force -File |
  113. Where-Object { $_.Extension -in @(".pyc", ".pyo") } |
  114. ForEach-Object { Remove-Item -LiteralPath $_.FullName -Force }
  115. }
  116. function New-Binary921PinMap([string]$SelectedProfile) {
  117. $reservedFutureUart = [ordered]@{
  118. UART1_TX = [ordered]@{ fpga_ball = "L10"; bank_io_net = "BANK2_GPIO52"; used = ($SelectedProfile -in @("formal-uart1-bmc-replay-binary921", "production-two-uart-bmc-replay-binary921")) }
  119. UART1_RX = [ordered]@{ fpga_ball = "M9"; bank_io_net = "BANK2_GPIO53"; used = ($SelectedProfile -in @("formal-uart1-bmc-replay-binary921", "production-two-uart-bmc-replay-binary921")) }
  120. UART2_TX = [ordered]@{ fpga_ball = "M10"; bank_io_net = "BANK2_GPIO54"; used = ($SelectedProfile -in @("formal-uart1-bmc-replay-binary921", "production-two-uart-bmc-replay-binary921")) }
  121. UART2_RX = [ordered]@{ fpga_ball = "N11"; bank_io_net = "BANK2_GPIO55"; used = ($SelectedProfile -in @("formal-uart1-bmc-replay-binary921", "production-two-uart-bmc-replay-binary921")) }
  122. }
  123. if ($SelectedProfile -eq "debug-photo-bmc-replay-binary921") {
  124. return [ordered]@{
  125. name = $SelectedProfile
  126. transport = "separate_host_debug_uart"
  127. bmc_source = "pc_replay_from_real_bmc_capture"
  128. live_bmc_link_status = "not_used"
  129. hardware_access_status = "photo_visible_header"
  130. uart_assignments = [ordered]@{
  131. bmc_replay_uart_tx = [ordered]@{ fpga_ball = "T4"; role = "pc_replay_bmc_tx" }
  132. bmc_replay_uart_rx = [ordered]@{ fpga_ball = "R5"; role = "pc_replay_bmc_rx" }
  133. host_uart_tx = [ordered]@{ fpga_ball = "P7"; role = "binary921_host_tx" }
  134. host_uart_rx = [ordered]@{ fpga_ball = "P8"; role = "binary921_host_rx" }
  135. debug_uart_rx = [ordered]@{ fpga_ball = "P10"; role = "binary921_debug_rx" }
  136. debug_uart_tx = [ordered]@{ fpga_ball = "R10"; role = "binary921_debug_tx" }
  137. }
  138. ptc_substitutions = [ordered]@{
  139. PTC03 = [ordered]@{ original_ball = "T4"; substitute_ball = "P5"; bank_io_net = "BANK2_GPIO40"; reason = "photo_visible_uart_overlap_remap" }
  140. PTC04 = [ordered]@{ original_ball = "R5"; substitute_ball = "T8"; bank_io_net = "BANK2_GPIO41"; reason = "photo_visible_uart_overlap_remap" }
  141. PTC17 = [ordered]@{ original_ball = "P8"; substitute_ball = "M14"; bank_io_net = "BANK2_GPIO42"; reason = "photo_visible_uart_overlap_remap" }
  142. PTC18 = [ordered]@{ original_ball = "P7"; substitute_ball = "M15"; bank_io_net = "BANK2_GPIO43"; reason = "photo_visible_uart_overlap_remap" }
  143. PTC21 = [ordered]@{ original_ball = "P10"; substitute_ball = "P15"; bank_io_net = "BANK2_GPIO44"; reason = "photo_visible_uart_overlap_remap" }
  144. PTC22 = [ordered]@{ original_ball = "R10"; substitute_ball = "N14"; bank_io_net = "BANK2_GPIO45"; reason = "photo_visible_uart_overlap_remap" }
  145. }
  146. reserved_future_uart = $reservedFutureUart
  147. }
  148. }
  149. if ($SelectedProfile -eq "production-two-uart-bmc-replay-binary921") {
  150. return [ordered]@{
  151. name = $SelectedProfile
  152. transport = "combined_host_debug_uart"
  153. bmc_source = "pc_replay_from_real_bmc_capture"
  154. live_bmc_link_status = "not_used"
  155. hardware_access_status = "production_uart1_uart2_access_confirmed_by_user"
  156. uart_assignments = [ordered]@{
  157. bmc_replay_uart_tx = [ordered]@{ fpga_ball = "L10"; role = "pc_replay_bmc_tx"; baud = 115200 }
  158. bmc_replay_uart_rx = [ordered]@{ fpga_ball = "M9"; role = "pc_replay_bmc_rx"; baud = 115200 }
  159. combined_debug_host_uart_tx = [ordered]@{ fpga_ball = "M10"; role = "binary921_combined_tx"; baud = 921600 }
  160. combined_debug_host_uart_rx = [ordered]@{ fpga_ball = "N11"; role = "binary921_combined_rx"; baud = 921600 }
  161. }
  162. ptc_substitutions = [ordered]@{}
  163. reserved_future_uart = $reservedFutureUart
  164. jtag = [ordered]@{
  165. connector = "J3 CON/2x5P/2.54"
  166. pinout = @("1=TCK", "2=GND", "3=TDO", "4=VREF", "5=TMS", "6=NC", "7=NC", "8=NC", "9=TDI", "10=GND")
  167. speed_hz = 200000
  168. program_mode = "PROGRAM_SRAM"
  169. power_cycle_required = $false
  170. }
  171. }
  172. }
  173. return [ordered]@{
  174. name = $SelectedProfile
  175. transport = "separate_host_debug_uart"
  176. bmc_source = "pc_replay_from_real_bmc_capture"
  177. live_bmc_link_status = "not_used"
  178. hardware_access_status = "blocked_waiting_for_uart1_uart2_access"
  179. uart_assignments = [ordered]@{
  180. bmc_replay_uart_tx = [ordered]@{ fpga_ball = "L10"; role = "pc_replay_bmc_tx" }
  181. bmc_replay_uart_rx = [ordered]@{ fpga_ball = "M9"; role = "pc_replay_bmc_rx" }
  182. host_uart_tx = [ordered]@{ fpga_ball = "M10"; role = "binary921_host_tx" }
  183. host_uart_rx = [ordered]@{ fpga_ball = "N11"; role = "binary921_host_rx" }
  184. debug_uart_rx = [ordered]@{ fpga_ball = "M14"; role = "binary921_debug_rx" }
  185. debug_uart_tx = [ordered]@{ fpga_ball = "M15"; role = "binary921_debug_tx" }
  186. }
  187. ptc_substitutions = [ordered]@{}
  188. reserved_future_uart = $reservedFutureUart
  189. }
  190. }
  191. function New-StartHere([string]$SelectedProfile) {
  192. $pinMap = New-Binary921PinMap $SelectedProfile
  193. if ($SelectedProfile -eq "production-two-uart-bmc-replay-binary921") {
  194. return @"
  195. # 生产温控板两串口 Binary921 包
  196. Profile: $SelectedProfile
  197. ## 现场顺序
  198. 1. 生产温控板先正常供电;本流程不要求重新上电,也不要求断电重插。
  199. 2. AL-Link 排线接生产板 `J3 CON/2x5P/2.54`,TD/BitWriter speed 设 `200k`。
  200. 3. 先启动 BMC replay。
  201. 4. 再启动 combined collector。
  202. 5. 看到 collector 等待 binary921 READY 后,手动执行 `PROGRAM_SRAM`,选择包根目录短 bitstream:
  203. ~~~text
  204. .\j6bin.bit
  205. ~~~
  206. 不要执行 flash/erase/spi flash。这个包只用于 SRAM;如果 BitWriter 识别不到器件,优先检查生产板是否已经外部供电,而不是先反复重启。
  207. ## JTAG J3 接线
  208. - 1=TCK
  209. - 2=GND
  210. - 3=TDO
  211. - 4=VREF
  212. - 5=TMS
  213. - 6=NC
  214. - 7=NC
  215. - 8=NC
  216. - 9=TDI
  217. - 10=GND
  218. `VREF` 不是给板子供电,只是 AL-Link 读取目标板 IO 电平参考。生产板必须另行正常供电;之前识别失败优先检查板子是否有电、排线方向、AL-Link 是否被 TD/BitWriter 独占、speed 是否为 200k。
  219. ## 两个串口
  220. - BMC replay UART1: TX=L10, RX=M9, 115200 8N1,接 PC replay,不接 live BMC。
  221. - Combined Debug+Host UART2: TX=M10, RX=N11, 921600 8N1,同一个 COM 口双向使用。
  222. ## 启动 BMC replay
  223. ~~~powershell
  224. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\replay-bmc.ps1 -BmcReplayPort COM9 -Payload .\bmc-replay-payload.json -Iterations 3 -TimeoutSeconds 600
  225. ~~~
  226. 该 payload 来自历史真实 BMC 样本:2 valid / 22 missing,DIMM1=30.75C,DIMM13=32.25C,reply SHA256 固化在 `manifest.json`。
  227. ## 启动 collector
  228. ~~~powershell
  229. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collect-binary921.ps1 -CombinedPort COM7 -Profile $SelectedProfile -OutputDir .\evidence-binary921 -DurationSeconds 180 -Bitstream .\j6bin.bit -TdReceipt .\td.json -BmcReplayReceipt .\bmc-replay-session.json
  230. ~~~
  231. collector 只打开显式 `-CombinedPort`,不枚举未知 COM,不安装 Python/pip/driver。Combined 口会写 Host binary command,也会从同一流读取 READY/ACK/debug frames。
  232. ## 边界
  233. - protocol=binary921。
  234. - transport=combined_host_debug_uart。
  235. - bmc_source=pc_replay_from_real_bmc_capture。
  236. - live_bmc_link_status=not_used。
  237. - real_fan_ptc_hardware_status=not_run,直到风扇/PTC 真实负载接线、极性和示波器/证据验证完成。
  238. - 不声明 flash、真实热性能、真实 PID 闭环或真实 PTC/FAN 负载通过。
  239. "@
  240. }
  241. $substitutionText = if ($SelectedProfile -eq "debug-photo-bmc-replay-binary921") {
  242. "PTC03/PTC04/PTC17/PTC18/PTC21/PTC22 use substitute spare GPIO in this debug-photo package. It does not claim full real HEAT pinout pass."
  243. } else {
  244. "HEAT/PTC/FAN/FG/INSTALL stay on real PDF/inventory pins. UART1/2 access and M14/M15 debug wiring still need board-level access verification."
  245. }
  246. return @"
  247. # J6 BMC-Replay Binary921 Package
  248. Profile: $SelectedProfile
  249. ## Order
  250. 1. Start the BMC replay window first.
  251. 2. Start the binary921 collector.
  252. 3. When the collector is waiting for READY, manually run PROGRAM_SRAM and select the root short bitstream:
  253. ~~~text
  254. .\j6bin.bit
  255. ~~~
  256. Before PROGRAM_SRAM, confirm board power is connected and set BitWriter/TD GUI JTAG speed 200k. A power-cycle is not required for this package; if the JTAG device is not detected, check board power first, then cable/AL-Link and speed.
  257. collector first, then PROGRAM_SRAM. Do not select a deep `bitstreams\...` path for BitWriter unless you are only auditing hashes.
  258. ## BMC replay
  259. Use a second PowerShell window:
  260. ~~~powershell
  261. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\replay-bmc.ps1 -BmcReplayPort COM9 -Payload .\bmc-replay-payload.example.json
  262. ~~~
  263. This writes `.\bmc-replay-session.json`. Strict evidence should replace the example payload with a real BMC capture normalized by `tools\bmc_replay_uart.py`. This package does not install Python, pip, drivers, or enumerate unknown COM ports.
  264. ## Collector
  265. Use a third PowerShell window:
  266. ~~~powershell
  267. powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collect-binary921.ps1 -HostPort COM8 -DebugPort COM7 -Profile $SelectedProfile -OutputDir .\evidence-binary921 -DurationSeconds 180 -Bitstream .\j6bin.bit -TdReceipt .\td.json -BmcReplayReceipt .\bmc-replay-session.json
  268. ~~~
  269. The collector writes binary HostPort commands and reads DebugPort binary921 frames. DebugPort is read-only.
  270. ## Pins
  271. - BMC replay UART TX=$($pinMap.uart_assignments.bmc_replay_uart_tx.fpga_ball), RX=$($pinMap.uart_assignments.bmc_replay_uart_rx.fpga_ball), 115200 8N1.
  272. - HostPort TX=$($pinMap.uart_assignments.host_uart_tx.fpga_ball), RX=$($pinMap.uart_assignments.host_uart_rx.fpga_ball), COM8, 115200 8N1.
  273. - DebugPort RX=$($pinMap.uart_assignments.debug_uart_rx.fpga_ball), TX=$($pinMap.uart_assignments.debug_uart_tx.fpga_ball), COM7, 921600 8N1.
  274. - $substitutionText
  275. ## Boundary
  276. - protocol=binary921.
  277. - bmc_source=pc_replay_from_real_bmc_capture.
  278. - live_bmc_link_status=not_used.
  279. - real_fan_ptc_hardware_status=not_run until real loads are wired and measured.
  280. - No flash, no driver install, no unknown COM enumeration, no DebugPort writes, no thermal performance claim, no PID closed-loop pass claim.
  281. "@
  282. }
  283. $repoRoot = Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..")
  284. $out = (Resolve-Path -LiteralPath (New-Item -ItemType Directory -Force -Path $OutputDir)).Path
  285. if ([string]::IsNullOrWhiteSpace($PackageName)) {
  286. $stamp = Get-Date -Format "yyyyMMdd-HHmmss"
  287. $PackageName = if ($Profile -eq "debug-photo-bmc-replay-binary921") {
  288. "j6bin-debug-photo-$stamp"
  289. } elseif ($Profile -eq "production-two-uart-bmc-replay-binary921") {
  290. "j6prod-2uart-bmc-replay-$stamp"
  291. } else {
  292. "j6bin-formal-uart1-$stamp"
  293. }
  294. }
  295. if ($Profile -eq "production-two-uart-bmc-replay-binary921") {
  296. Assert-ProductionTdReceipt $TdReceipt $Bitstream $Profile | Out-Null
  297. if ([string]::IsNullOrWhiteSpace($BmcReplayPayload)) {
  298. throw "BmcReplayPayload is required for production-two-uart-bmc-replay-binary921"
  299. }
  300. Assert-ProductionBmcPayload $BmcReplayPayload | Out-Null
  301. }
  302. $stage = Join-Path $out $PackageName
  303. if (Test-Path -LiteralPath $stage) {
  304. if (-not $ForceOverwrite) {
  305. throw "Package staging directory already exists: $stage"
  306. }
  307. Remove-Item -LiteralPath $stage -Recurse -Force
  308. }
  309. foreach ($dir in @("bitstreams", "td-receipts", "tools", "commands", "config")) {
  310. New-Item -ItemType Directory -Force -Path (Join-Path $stage $dir) | Out-Null
  311. }
  312. Copy-IntoPackage $Bitstream $stage $ShortBitName | Out-Null
  313. Copy-IntoPackage $Bitstream (Join-Path $stage "bitstreams") | Out-Null
  314. Copy-IntoPackage $TdReceipt $stage $ShortTdName | Out-Null
  315. Copy-IntoPackage $TdReceipt (Join-Path $stage "td-receipts") | Out-Null
  316. Copy-IntoPackage (Join-Path $repoRoot "tools\remote\collect_j6_binary921.py") (Join-Path $stage "tools") | Out-Null
  317. Copy-IntoPackage (Join-Path $repoRoot "tools\binary921.py") (Join-Path $stage "tools") | Out-Null
  318. Copy-IntoPackage (Join-Path $repoRoot "tools\bmc_replay_uart.py") (Join-Path $stage "tools") | Out-Null
  319. Copy-IntoPackage (Join-Path $repoRoot "config\pin_inventory.fcb_fpga_mcu0611.json") (Join-Path $stage "config") | Out-Null
  320. $bmcReplayPayloadInfo = $null
  321. if ($Profile -eq "production-two-uart-bmc-replay-binary921") {
  322. $payloadTarget = Copy-IntoPackage $BmcReplayPayload $stage "bmc-replay-payload.json"
  323. $payloadJson = Assert-ProductionBmcPayload $payloadTarget
  324. $bmcReplayPayloadInfo = [ordered]@{
  325. path = "bmc-replay-payload.json"
  326. sha256 = Get-Sha256 $payloadTarget
  327. reply_sha256 = [string]$payloadJson.reply_sha256
  328. capture_text_sha256 = [string]$payloadJson.capture_text_sha256
  329. byte_count = [int]$payloadJson.byte_count
  330. valid_count = [int]$payloadJson.valid_count
  331. missing_count = [int]$payloadJson.missing_count
  332. source = [string]$payloadJson.source
  333. }
  334. }
  335. $collectorWrapper = @'
  336. param(
  337. [string]$HostPort = "COM8",
  338. [string]$DebugPort = "COM7",
  339. [string]$CombinedPort = "",
  340. [ValidateSet("debug-photo-bmc-replay-binary921", "formal-uart1-bmc-replay-binary921", "production-two-uart-bmc-replay-binary921")]
  341. [string]$Profile = "__PROFILE__",
  342. [string]$OutputDir = ".\evidence-binary921",
  343. [int]$DurationSeconds = 180,
  344. [string]$Bitstream = ".\j6bin.bit",
  345. [string]$TdReceipt = ".\td.json",
  346. [string]$BmcReplayReceipt = ".\bmc-replay-session.json",
  347. [switch]$SelfTest
  348. )
  349. $ErrorActionPreference = "Stop"
  350. $root = $PSScriptRoot
  351. $python = "python"
  352. $collector = Join-Path $root "tools\collect_j6_binary921.py"
  353. $env:PYTHONDONTWRITEBYTECODE = "1"
  354. if ($SelfTest) {
  355. & $python $collector --selftest
  356. } else {
  357. if ($Profile -eq "production-two-uart-bmc-replay-binary921") {
  358. if ([string]::IsNullOrWhiteSpace($CombinedPort)) { throw "CombinedPort is required for production-two-uart-bmc-replay-binary921" }
  359. & $python $collector --transport combined-single-com --combined-port $CombinedPort --profile $Profile --output-dir $OutputDir --duration-sec $DurationSeconds --bitstream $Bitstream --td-receipt $TdReceipt --bmc-replay-receipt $BmcReplayReceipt --json
  360. } else {
  361. & $python $collector --transport two-uart --host-port $HostPort --debug-port $DebugPort --profile $Profile --output-dir $OutputDir --duration-sec $DurationSeconds --bitstream $Bitstream --td-receipt $TdReceipt --bmc-replay-receipt $BmcReplayReceipt --json
  362. }
  363. }
  364. if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
  365. '@
  366. $collectorWrapper = $collectorWrapper.Replace("__PROFILE__", $Profile)
  367. Set-Content -LiteralPath (Join-Path $stage "collect-binary921.ps1") -Encoding UTF8 -Value $collectorWrapper
  368. if ($Profile -eq "production-two-uart-bmc-replay-binary921") {
  369. Set-Content -LiteralPath (Join-Path $stage "commands\collect-binary921-template.ps1") -Encoding UTF8 -Value ('powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collect-binary921.ps1 -CombinedPort COM7 -Profile {0} -OutputDir .\evidence-binary921 -DurationSeconds 180 -Bitstream .\j6bin.bit -TdReceipt .\td.json -BmcReplayReceipt .\bmc-replay-session.json' -f $Profile)
  370. } else {
  371. Set-Content -LiteralPath (Join-Path $stage "commands\collect-binary921-template.ps1") -Encoding UTF8 -Value ('powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collect-binary921.ps1 -HostPort COM8 -DebugPort COM7 -Profile {0} -OutputDir .\evidence-binary921 -DurationSeconds 180 -Bitstream .\j6bin.bit -TdReceipt .\td.json -BmcReplayReceipt .\bmc-replay-session.json' -f $Profile)
  372. }
  373. $replayWrapper = @'
  374. param(
  375. [ValidatePattern('^COM[0-9]+$')]
  376. [string]$BmcReplayPort = "COM9",
  377. [string]$Payload = "__BMC_PAYLOAD_DEFAULT__",
  378. [int]$Iterations = 3,
  379. [int]$TimeoutSeconds = 600,
  380. [switch]$SelfTest
  381. )
  382. $ErrorActionPreference = "Stop"
  383. $root = $PSScriptRoot
  384. $helper = Join-Path $root "tools\bmc_replay_uart.py"
  385. $env:PYTHONDONTWRITEBYTECODE = "1"
  386. if ($SelfTest) {
  387. & python $helper selftest
  388. } else {
  389. & python $helper replay --port $BmcReplayPort --payload $Payload --iterations $Iterations --timeout-sec $TimeoutSeconds --json | Tee-Object -FilePath (Join-Path $root "bmc-replay-session.json")
  390. }
  391. if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
  392. '@
  393. $replayWrapper = $replayWrapper.Replace("__BMC_PAYLOAD_DEFAULT__", ($(if ($Profile -eq "production-two-uart-bmc-replay-binary921") { ".\bmc-replay-payload.json" } else { ".\bmc-replay-payload.example.json" })))
  394. Set-Content -LiteralPath (Join-Path $stage "replay-bmc.ps1") -Encoding UTF8 -Value $replayWrapper
  395. $examplePayload = [ordered]@{
  396. schema = "j6-bmc-replay-payload-v1"
  397. status = "debug_example_only"
  398. source = "synthetic_example"
  399. bmc_source = "pc_replay_from_real_bmc_capture"
  400. live_bmc_link_status = "not_used"
  401. replay_mode = "poll_response"
  402. poll_text = "ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03"
  403. poll_command_text = "ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03`n"
  404. 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"
  405. byte_count = 48
  406. valid_count = 24
  407. missing_count = 0
  408. authority_boundary = "Synthetic example payload for temporary BMC replay wiring debug only. It is not real BMC evidence."
  409. }
  410. $examplePayload | ConvertTo-Json -Depth 16 | Set-Content -LiteralPath (Join-Path $stage "bmc-replay-payload.example.json") -Encoding UTF8
  411. Set-Content -LiteralPath (Join-Path $stage "START-HERE.zh-CN.md") -Encoding UTF8 -Value (New-StartHere $Profile)
  412. $pinMap = New-Binary921PinMap $Profile
  413. $packageStatus = if ($Profile -eq "formal-uart1-bmc-replay-binary921") {
  414. "blocked_waiting_for_uart1_uart2_access"
  415. } else {
  416. "pass"
  417. }
  418. $transport = if ($Profile -eq "production-two-uart-bmc-replay-binary921") { "combined_host_debug_uart" } else { "separate_host_debug_uart" }
  419. $manifest = [ordered]@{
  420. schema = "j6-bmc-replay-binary921-package-manifest-v1"
  421. status = $packageStatus
  422. generated_at = (Get-Date).ToUniversalTime().ToString("o")
  423. package_name = $PackageName
  424. protocol = "binary921"
  425. pin_profile = $Profile
  426. transport = $transport
  427. combined_uart_baud = $(if ($transport -eq "combined_host_debug_uart") { 921600 } else { $null })
  428. bmc_replay_uart_baud = 115200
  429. programming_mode = "PROGRAM_SRAM"
  430. jtag_programming = [ordered]@{
  431. program_mode = "PROGRAM_SRAM"
  432. jtag_speed_hz = 200000
  433. board_power_present_before_program = $true
  434. power_cycle_required = $false
  435. connector = "J3 CON/2x5P/2.54"
  436. pinout = @("1=TCK", "2=GND", "3=TDO", "4=VREF", "5=TMS", "6=NC", "7=NC", "8=NC", "9=TDI", "10=GND")
  437. tooling = "manual BitWriter/TD GUI"
  438. cli_programming_supported = $false
  439. cli_speed_mapping_proven = $false
  440. }
  441. bitstream = [ordered]@{ path = $ShortBitName; sha256 = Get-Sha256 (Join-Path $stage $ShortBitName) }
  442. td_receipt = [ordered]@{ path = $ShortTdName; sha256 = Get-Sha256 (Join-Path $stage $ShortTdName) }
  443. bmc_source = "pc_replay_from_real_bmc_capture"
  444. live_bmc_link_status = "not_used"
  445. bmc_replay_payload = $bmcReplayPayloadInfo
  446. pin_map = $pinMap
  447. real_fan_ptc_hardware_status = "not_run"
  448. hardware_access_status = $pinMap.hardware_access_status
  449. collector = [ordered]@{
  450. wrapper = "collect-binary921.ps1"
  451. python = "tools/collect_j6_binary921.py"
  452. transport = $transport
  453. host_port = $(if ($transport -eq "combined_host_debug_uart") { $null } else { "COM8" })
  454. debug_port = $(if ($transport -eq "combined_host_debug_uart") { $null } else { "COM7" })
  455. combined_port = $(if ($transport -eq "combined_host_debug_uart") { "COM7" } else { $null })
  456. debug_port_write_policy = $(if ($transport -eq "combined_host_debug_uart") { "combined_port_writes_host_commands_only" } else { "read_only" })
  457. bmc_replay_receipt = "bmc-replay-session.json"
  458. expected_artifact = "binary921-evidence-manifest.json"
  459. }
  460. host_control_commands = @("SET_PTC 1 10", "SET_PTC 24 20", "SET_FAN 1 40", "SET_FAN 4 30", "SET_PID_REQUESTED 1", "GET_STATUS", "GET_MAP", "GET_SENSOR", "GET_SENSOR", "GET_SENSOR", "SET_PID_REQUESTED 0", "DISABLE")
  461. safety = [ordered]@{
  462. flash_attempted = $false
  463. driver_install_attempted = $false
  464. programs_nonvolatile = $false
  465. enumerates_com_ports = $false
  466. debug_port_writes_to_serial = $false
  467. toggles_dtr_rts = $false
  468. }
  469. authority_boundary = "SRAM-only binary921 diagnostic package. It does not claim live BMC, thermal performance, PID closed-loop, or real PTC/FAN load pass."
  470. }
  471. $manifest | ConvertTo-Json -Depth 64 | Set-Content -LiteralPath (Join-Path $stage "manifest.json") -Encoding UTF8
  472. Remove-PythonCache $stage
  473. $inventory = New-Object System.Collections.Generic.List[object]
  474. Get-ChildItem -LiteralPath $stage -Recurse -File | Sort-Object FullName | ForEach-Object {
  475. if ($_.Name -eq "sha256-inventory.json") { return }
  476. $inventory.Add((New-InventoryItem $_.FullName $stage)) | Out-Null
  477. }
  478. [ordered]@{
  479. schema = "j6-bmc-replay-binary921-package-sha256-inventory-v1"
  480. generated_at = (Get-Date).ToUniversalTime().ToString("o")
  481. self_hash_policy = "excluded_self_referential_file"
  482. inventory = $inventory
  483. } | ConvertTo-Json -Depth 32 | Set-Content -LiteralPath (Join-Path $stage "sha256-inventory.json") -Encoding UTF8
  484. $zipPath = Join-Path $out ($PackageName + ".zip")
  485. if (Test-Path -LiteralPath $zipPath) {
  486. if (-not $ForceOverwrite) { throw "Package zip already exists: $zipPath" }
  487. Remove-Item -LiteralPath $zipPath -Force
  488. }
  489. $zipSidecar = $zipPath + ".sha256.txt"
  490. if (Test-Path -LiteralPath $zipSidecar) {
  491. if (-not $ForceOverwrite) { throw "Package zip sidecar already exists: $zipSidecar" }
  492. Remove-Item -LiteralPath $zipSidecar -Force
  493. }
  494. Compress-Archive -Path (Join-Path $stage "*") -DestinationPath $zipPath -Force
  495. $zipSha = Get-Sha256 $zipPath
  496. Set-Content -LiteralPath $zipSidecar -Encoding ASCII -Value ("{0} {1}" -f $zipSha, (Split-Path -Leaf $zipPath))
  497. Write-Host "Wrote $stage"
  498. Write-Host "Wrote $zipPath"
  499. Write-Host ("SHA256 {0} {1}" -f $zipSha, $zipPath)