| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821 |
- param(
- [string]$OutputDir = ".\j6tmp-v2-tailfix-package",
- [string]$PackageName = "",
- [Parameter(Mandatory = $true)]
- [ValidateSet("temp-uart-ptc-remap", "debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")]
- [string]$Profile,
- [string]$Bitstream = "",
- [Parameter(Mandatory = $true)]
- [string]$TdReceipt,
- [switch]$FormalBlocked,
- [switch]$ForceOverwrite
- )
- $ErrorActionPreference = "Stop"
- # Package profile:
- # temp-uart-ptc-remap -> j6tmp-v2-tailfix
- # debug-photo-uart-bmc-replay/formal-uart1-bmc-replay -> j6-bmc-replay package profiles
- # The copied collector is tools\remote\collect-j6-host-sensor-real-fan-ptc.ps1.
- # The copied BMC replay helper is tools\bmc_replay_uart.py.
- # Start BMC replay first, then collector, then manual PROGRAM_SRAM so READY/J6READY is captured.
- $ShortBitName = "j6tmp.bit"
- $ShortTdName = "td.json"
- function Get-Sha256([string]$Path) {
- if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
- throw "File not found: $Path"
- }
- return (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant()
- }
- function Get-StringSha256([string]$Text) {
- $sha = [System.Security.Cryptography.SHA256]::Create()
- try {
- $bytes = [System.Text.Encoding]::ASCII.GetBytes($Text)
- $hash = $sha.ComputeHash($bytes)
- return ([System.BitConverter]::ToString($hash)).Replace("-", "").ToLowerInvariant()
- } finally {
- $sha.Dispose()
- }
- }
- function Copy-IntoPackage([string]$Source, [string]$DestinationDir) {
- if (-not (Test-Path -LiteralPath $Source -PathType Leaf)) {
- throw "File not found: $Source"
- }
- New-Item -ItemType Directory -Force -Path $DestinationDir | Out-Null
- $name = Split-Path -Leaf $Source
- $destination = Join-Path $DestinationDir $name
- Copy-Item -LiteralPath $Source -Destination $destination -Force
- return $destination
- }
- function New-InventoryItem([string]$Path, [string]$Root) {
- $full = (Resolve-Path -LiteralPath $Path).Path
- $base = (Resolve-Path -LiteralPath $Root).Path.TrimEnd('\')
- $relative = $full.Substring($base.Length).TrimStart('\').Replace('\', '/')
- return [ordered]@{
- path = $relative
- sha256 = Get-Sha256 $full
- bytes = (Get-Item -LiteralPath $full).Length
- }
- }
- function New-PinMap([string]$SelectedProfile) {
- $commonReservedFutureUart = [ordered]@{
- UART1_TX = [ordered]@{ fpga_ball = "L10"; bank_io_net = "BANK2_GPIO52"; used = ($SelectedProfile -eq "formal-uart1-bmc-replay") }
- UART1_RX = [ordered]@{ fpga_ball = "M9"; bank_io_net = "BANK2_GPIO53"; used = ($SelectedProfile -eq "formal-uart1-bmc-replay") }
- UART2_TX = [ordered]@{ fpga_ball = "M10"; bank_io_net = "BANK2_GPIO54"; used = ($SelectedProfile -eq "formal-uart1-bmc-replay") }
- UART2_RX = [ordered]@{ fpga_ball = "N11"; bank_io_net = "BANK2_GPIO55"; used = ($SelectedProfile -eq "formal-uart1-bmc-replay") }
- }
- if ($SelectedProfile -eq "temp-uart-ptc-remap") {
- return [ordered]@{
- name = "temp-uart-ptc-remap"
- bmc_tx_ball = "T4"
- bmc_rx_ball = "R5"
- host_tx_ball = "P7"
- host_rx_ball = "P8"
- debug_rx_ball = "P10"
- debug_tx_ball = "R10"
- ptc_substitutions = [ordered]@{
- PTC03 = [ordered]@{ original_ball = "T4"; substitute_ball = "P5"; bank_io_net = "BANK2_GPIO40" }
- PTC04 = [ordered]@{ original_ball = "R5"; substitute_ball = "T8"; bank_io_net = "BANK2_GPIO41" }
- PTC17 = [ordered]@{ original_ball = "P8"; substitute_ball = "M14"; bank_io_net = "BANK2_GPIO42" }
- PTC18 = [ordered]@{ original_ball = "P7"; substitute_ball = "M15"; bank_io_net = "BANK2_GPIO43" }
- PTC21 = [ordered]@{ original_ball = "P10"; substitute_ball = "P15"; bank_io_net = "BANK2_GPIO44" }
- PTC22 = [ordered]@{ original_ball = "R10"; substitute_ball = "N14"; bank_io_net = "BANK2_GPIO45" }
- }
- reserved_future_uart = $commonReservedFutureUart
- }
- }
- if ($SelectedProfile -eq "debug-photo-uart-bmc-replay") {
- return [ordered]@{
- name = "debug-photo-uart-bmc-replay"
- bmc_source = "pc_replay_from_real_bmc_capture"
- live_bmc_link_status = "not_used"
- hardware_access_status = "photo_visible_header"
- bmc_tx_ball = "T4"
- bmc_rx_ball = "R5"
- host_tx_ball = "P7"
- host_rx_ball = "P8"
- debug_rx_ball = "P10"
- debug_tx_ball = "R10"
- uart_assignments = [ordered]@{
- bmc_replay_uart_tx = [ordered]@{ fpga_ball = "T4"; role = "pc_replay_bmc_tx" }
- bmc_replay_uart_rx = [ordered]@{ fpga_ball = "R5"; role = "pc_replay_bmc_rx" }
- host_uart_tx = [ordered]@{ fpga_ball = "P7"; role = "host_control_tx" }
- host_uart_rx = [ordered]@{ fpga_ball = "P8"; role = "host_control_rx" }
- debug_uart_rx = [ordered]@{ fpga_ball = "P10"; role = "debug921_rx" }
- debug_uart_tx = [ordered]@{ fpga_ball = "R10"; role = "debug921_tx" }
- }
- ptc_substitutions = [ordered]@{
- PTC03 = [ordered]@{ original_ball = "T4"; substitute_ball = "P5"; bank_io_net = "BANK2_GPIO40"; reason = "photo_visible_uart_overlap_remap" }
- PTC04 = [ordered]@{ original_ball = "R5"; substitute_ball = "T8"; bank_io_net = "BANK2_GPIO41"; reason = "photo_visible_uart_overlap_remap" }
- PTC17 = [ordered]@{ original_ball = "P8"; substitute_ball = "M14"; bank_io_net = "BANK2_GPIO42"; reason = "photo_visible_uart_overlap_remap" }
- PTC18 = [ordered]@{ original_ball = "P7"; substitute_ball = "M15"; bank_io_net = "BANK2_GPIO43"; reason = "photo_visible_uart_overlap_remap" }
- PTC21 = [ordered]@{ original_ball = "P10"; substitute_ball = "P15"; bank_io_net = "BANK2_GPIO44"; reason = "photo_visible_uart_overlap_remap" }
- PTC22 = [ordered]@{ original_ball = "R10"; substitute_ball = "N14"; bank_io_net = "BANK2_GPIO45"; reason = "photo_visible_uart_overlap_remap" }
- }
- reserved_future_uart = $commonReservedFutureUart
- }
- }
- if ($SelectedProfile -eq "formal-uart1-bmc-replay") {
- return [ordered]@{
- name = "formal-uart1-bmc-replay"
- bmc_source = "pc_replay_from_real_bmc_capture"
- live_bmc_link_status = "not_used"
- hardware_access_status = "blocked_waiting_for_uart1_uart2_access"
- bmc_tx_ball = "L10"
- bmc_rx_ball = "M9"
- host_tx_ball = "M10"
- host_rx_ball = "N11"
- debug_rx_ball = "P15"
- debug_tx_ball = "N14"
- uart_assignments = [ordered]@{
- bmc_replay_uart_tx = [ordered]@{ fpga_ball = "L10"; role = "pc_replay_bmc_tx" }
- bmc_replay_uart_rx = [ordered]@{ fpga_ball = "M9"; role = "pc_replay_bmc_rx" }
- host_uart_tx = [ordered]@{ fpga_ball = "M10"; role = "host_control_tx" }
- host_uart_rx = [ordered]@{ fpga_ball = "N11"; role = "host_control_rx" }
- debug_uart_rx = [ordered]@{ fpga_ball = "P15"; role = "debug921_rx" }
- debug_uart_tx = [ordered]@{ fpga_ball = "N14"; role = "debug921_tx" }
- }
- ptc_substitutions = [ordered]@{}
- reserved_future_uart = $commonReservedFutureUart
- }
- }
- throw "Unsupported profile: $SelectedProfile"
- }
- function New-StartHereText([string]$SelectedProfile, [string]$BitName, [string]$TdName, [string]$ShortBit, [string]$ShortTd) {
- $pinMap = New-PinMap $SelectedProfile
- $isBmcReplay = $SelectedProfile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")
- $title = if ($isBmcReplay) { "J6 BMC replay Debug921 short-path package" } else { "J6 temp-uart-ptc-remap Debug921 v2 tailfix short-path package" }
- $ptcLine = if ($SelectedProfile -eq "formal-uart1-bmc-replay") {
- "- HEAT/PTC/FAN/FG/INSTALL use the PDF/inventory real schematic pins; no PTC substitution is active in this formal profile."
- } else {
- "- PTC03/PTC04/PTC17/PTC18/PTC21/PTC22 使用临时替代引脚;具体替代关系见 manifest.json。"
- }
- $wiring = @"
- - BMC UART:CPLD TX=$($pinMap.bmc_tx_ball),RX=$($pinMap.bmc_rx_ball)。
- - BMC source:pc_replay_from_real_bmc_capture,live_bmc_link_status=not_used。
- - DebugPort:COM7,CPLD RX=$($pinMap.debug_rx_ball),TX=$($pinMap.debug_tx_ball),921600 8N1。
- - HostPort:COM8,CPLD TX=$($pinMap.host_tx_ball),RX=$($pinMap.host_rx_ball),115200 8N1。
- - BmcReplayPort:COM9,115200 8N1,由 replay-bmc.ps1 只在看到 CPLD poll 后回复。
- $ptcLine
- - HostPort 上电后先输出 READY profile=temp-uart-ptc-remap seq=00000000。collector 会等待 HostPort READY 和 DebugPort J6READY 都出现,保存 startup-preflight.json,再进入严格 12 条正式命令序列。
- - collector_protocol_profile=temp-uart-ptc-remap:这是当前 RTL/collector 的 READY/J6READY 协议别名,不改变本包 pin_profile=$SelectedProfile。
- "@
- $hardwareNote = if ($SelectedProfile -eq "formal-uart1-bmc-replay") {
- "本 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。"
- } elseif ($SelectedProfile -eq "debug-photo-uart-bmc-replay") {
- "本 debug-photo-uart-bmc-replay profile 保持照片可见调试串口接线,BMC 链路改为 PC replay,并把 6 路与串口冲突的 PTC 输出临时改到复核空闲 GPIO;hardware_access_status=photo_visible_header。"
- } else {
- "本 temp profile 保持当前三路调试串口接线不变,只把 6 路与串口冲突的 PTC 输出临时改到复核空闲 GPIO。"
- }
- return @"
- # $title
- ## 1. 先准备并启动 BMC replay
- 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。
- 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.
- ~~~powershell
- powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\capture-bmc.ps1 -Input .\bmc-capture.txt -Payload .\bmc-replay-payload.json
- powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\replay-bmc.ps1 -BmcReplayPort COM9 -Payload .\bmc-replay-payload.json
- ~~~
- 临时只想验证 CPLD poll/response 链路时,也可以先用包内 bmc-replay-payload.example.json:
- ~~~powershell
- powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\replay-bmc.ps1 -BmcReplayPort COM9 -Payload .\bmc-replay-payload.example.json
- ~~~
- example payload 只能用于 debug fallback;严格 evidence 里 BMC source 仍应来自 `capture-bmc.ps1` 规范化的真实 BMC capture。
- 若 Windows 机器还没有 Python,请先由用户手动安装 Python;本包不会自动安装 Python/pip/driver。
- ## 2. 再启动 collector
- 确认 replay-bmc.ps1 已经在单独窗口等待后,在本包根目录打开另一个 PowerShell,复制执行下面这一条命令。collector 会先打开 COM8/COM7、等待 READY/J6READY,并把启动同步写入 startup-preflight.json。
- 端口参数:-HostPort COM8 -DebugPort COM7 -BmcReplayPort COM9
- ~~~powershell
- 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
- ~~~
- 也可以执行包内快捷脚本:
- ~~~powershell
- powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\commands\collect-template.ps1
- ~~~
- ## 3. collector 启动后手动刷 SRAM
- 刷 SRAM 前先确认板子外部电源已经接好,BitWriter/TD GUI 能识别 JTAG 链。现场有效设置是 JTAG speed 200k + board power present + PROGRAM_SRAM。
- 不要求重新上电;如果 JTAG/BitWriter 识别不到器件,第一检查项是板子电源是否接好,其次才是 JTAG 线束、AL-Link 和 speed 设置。
- collector 开始等待后,在 TD/ChipWatcher/BitWriter 中只执行 PROGRAM_SRAM,选择本包根目录下面这个短路径 bitstream:
- ~~~text
- .\$ShortBit
- ~~~
- 不要选择 bitstreams/$BitName 作为现场刷机主路径;那份长文件名副本只用于审计和 hash 对照。若 BitWriter 报 Cannot open file,第一检查项是是否误选了旧长包或 bitstreams 深目录里的长文件名 bitstream。
- 不要执行任何非易失存储写入、擦除或固化存储相关动作。
- collector first, then PROGRAM_SRAM. collector 会忽略 READY/J6READY 前的旧程序 ACK,并在未锁定新 SRAM epoch 时拒绝发送正式命令。
- ## 接线
- $wiring
- ## 采集内容
- - 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。
- - startup-preflight.json 记录 READY/J6READY epoch 锁定和 pre-SRAM noise;正式 transcript 必须仍然只有 12 条命令和 12 条匹配 ACK。
- - DebugPort 只读,预期证据帧包括 J6CMD/J6RAW/J6EVT/J6PWM/J6MOD/J6STAT/J6MAP/J6TEMP。
- - collector 结束前会执行 tail drain,等待 DebugPort 静默并记录最后 J6STAT 是否覆盖最后完整 J6RAW;若末尾只有不完整行,会记录到 manifest/debug-frame-stream,不会当作有效 replay 帧。
- - BMC 温度仍来自 J6 UART raw 命令,不使用 I2C、MCU、BMC_SCL/SDA 或 TEMP_SCL/SDA。
- ## 包内参考
- - [中文 runbook](docs/j6-host-sensor-real-fan-ptc-debug921-runbook.zh-CN.md)
- - [collector 脚本](collector/collect-j6-host-sensor-real-fan-ptc.ps1)
- - [SHA256 inventory](sha256-inventory.json)
- ## 边界
- $hardwareNote
- 本包只声明 SRAM-only 诊断链路、HostPort 控制、BMC raw 采样、温度解析和证据采集成立;不声明非易失存储写入、真实热性能、真实 PTC/FAN 负载或 PID 闭环通过。
- "@
- }
- function New-FormalBlockedText([string]$SelectedProfile) {
- $pinMap = New-PinMap $SelectedProfile
- return @"
- # J6 BMC replay formal-uart1 blocked package
- 本包不是可刷机包,不能刷机。
- ## 结论
- - status=blocked_td_mslice_over_limit
- - 最新 formal-uart1-bmc-replay P15/N14 DebugPort 尝试结果为 1137 mslices,器件限制为 1120 mslices。
- - 历史最佳 T8/P5 DebugPort 候选观察到 1131 mslices,仍超过 1120 限制。
- - 因此本轮没有生成 formal-uart1-bmc-replay SRAM bitstream,也没有短路径 bitstream 别名。
- - 不能把 debug-photo-uart-bmc-replay 的 bitstream 当作 formal 版使用,因为 debug-photo 版仍有 6 路 PTC remap,formal 版目标是全 HEAT/PTC/FAN 使用真实原理图引脚。
- ## formal 设计方向
- - BMC-Replay UART:CPLD TX=$($pinMap.bmc_tx_ball),RX=$($pinMap.bmc_rx_ball),PC 串口回放真实 BMC capture。
- - HostPort:CPLD TX=$($pinMap.host_tx_ball),RX=$($pinMap.host_rx_ball)。
- - DebugPort 候选:CPLD TX=$($pinMap.debug_tx_ball),RX=$($pinMap.debug_rx_ball)。这是 SPARE_GPIO44/45 候选,不占 HEAT/FAN/FG/INSTALL、UART1/2、时钟、复位或 LED。
- - HEAT1..24、FAN_PWM1..4、FAN_FG1..8、FAN_INSTALL1..4 保持 PDF/inventory 真实映射。
- ## 还需要什么才可发布 formal 可刷包
- 1. 先做 debug921 RTL 资源削减或 TD packing 策略实验,至少减少 11 个 mslices,并保留 UART/Host/BMC replay/Debug evidence 行为。
- 2. 重新跑 TD build,必须实际生成 formal `.bit`。
- 3. 重新跑 package/selftest/hash/safety scan。
- 4. UART1/2 与 DebugPort 候选脚还需要现场连通性或可接线复核;在复核前 hardware_access_status 仍为 blocked_waiting_for_uart1_uart2_access。
- ## 边界
- - BMC source=pc_replay_from_real_bmc_capture,不声明 live_bmc_pass。
- - real_fan_ptc_hardware_status=not_run。
- - 不声明 flash、真实热性能、真实 PID 闭环或真实 PTC/FAN 负载通过。
- 包内 `td.json` 是 TD 失败 receipt,`manifest.json` 是本 blocked 包的机器可读说明。
- "@
- }
- $repoRoot = Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..")
- $out = (Resolve-Path -LiteralPath (New-Item -ItemType Directory -Force -Path $OutputDir)).Path
- if ($FormalBlocked -and $Profile -ne "formal-uart1-bmc-replay") {
- throw "-FormalBlocked is only valid with -Profile formal-uart1-bmc-replay."
- }
- if (-not $FormalBlocked -and [string]::IsNullOrWhiteSpace($Bitstream)) {
- throw "-Bitstream is required unless -FormalBlocked is specified."
- }
- if ([string]::IsNullOrWhiteSpace($PackageName)) {
- $stamp = Get-Date -Format "yyyyMMdd-HHmmss"
- $PackageName = "j6tmp-v2-tailfix-$stamp"
- }
- $stage = Join-Path $out $PackageName
- if (Test-Path -LiteralPath $stage) {
- if (-not $ForceOverwrite) {
- throw "Package staging directory already exists: $stage. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
- }
- $resolvedStage = (Resolve-Path -LiteralPath $stage).Path
- $resolvedOut = (Resolve-Path -LiteralPath $out).Path.TrimEnd('\')
- if (-not $resolvedStage.StartsWith($resolvedOut, [System.StringComparison]::OrdinalIgnoreCase)) {
- throw "Refusing to remove package directory outside output dir: $resolvedStage"
- }
- Remove-Item -LiteralPath $resolvedStage -Recurse -Force
- }
- foreach ($dir in @("bitstreams", "td-receipts", "collector", "commands", "schemas", "docs", "config", "bmc-replay")) {
- New-Item -ItemType Directory -Force -Path (Join-Path $stage $dir) | Out-Null
- }
- $collectorPath = Join-Path $repoRoot "tools\remote\collect-j6-host-sensor-real-fan-ptc.ps1"
- $bmcReplayPath = Join-Path $repoRoot "tools\bmc_replay_uart.py"
- $schemaPath = Join-Path $repoRoot "schemas\real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt.schema.json"
- $runbookPath = Join-Path $repoRoot "docs\j6-host-sensor-real-fan-ptc-debug921-runbook.zh-CN.md"
- $pinInventoryPath = Join-Path $repoRoot "config\pin_inventory.fcb_fpga_mcu0611.json"
- if ($FormalBlocked) {
- $tdReceiptCopy = Copy-IntoPackage $TdReceipt (Join-Path $stage "td-receipts")
- Copy-IntoPackage $schemaPath (Join-Path $stage "schemas") | Out-Null
- Copy-IntoPackage $runbookPath (Join-Path $stage "docs") | Out-Null
- Copy-IntoPackage $pinInventoryPath (Join-Path $stage "config") | Out-Null
- Copy-Item -LiteralPath $tdReceiptCopy -Destination (Join-Path $stage $ShortTdName) -Force
- Set-Content -LiteralPath (Join-Path $stage "START-HERE.zh-CN.md") -Encoding UTF8 -Value (New-FormalBlockedText $Profile)
- Set-Content -LiteralPath (Join-Path $stage "FORMAL-BLOCKED.zh-CN.md") -Encoding UTF8 -Value (New-FormalBlockedText $Profile)
- $pinMap = New-PinMap $Profile
- $manifest = [ordered]@{
- schema = "j6-host-sensor-real-fan-ptc-debug921-package-manifest-v1"
- status = "blocked_td_mslice_over_limit"
- generated_at = (Get-Date).ToUniversalTime().ToString("o")
- package_name = $PackageName
- diagnostic_scope = "host_sensor_real_fan_ptc_debug921"
- pin_profile = $Profile
- programming_mode = "not_available"
- bitstream = $null
- td_receipt = [ordered]@{ path = $ShortTdName; sha256 = Get-Sha256 (Join-Path $stage $ShortTdName) }
- blocked_reason = [ordered]@{
- code = "blocked_td_mslice_over_limit"
- latest_attempt_mslices = 1137
- latest_attempt_debug_uart_rx_ball = "P15"
- latest_attempt_debug_uart_tx_ball = "N14"
- best_observed_mslices = 1131
- best_observed_debug_uart_rx_ball = "T8"
- best_observed_debug_uart_tx_ball = "P5"
- device_mslice_limit = 1120
- no_flashable_formal_bitstream = $true
- }
- bmc_source = "pc_replay_from_real_bmc_capture"
- live_bmc_link_status = "not_used"
- pin_map = $pinMap
- real_fan_ptc_hardware_status = "not_run"
- remote_dependencies = "None for this blocked package."
- authority_boundary = "Blocked formal package. It records TD failure evidence only and must not be used for device programming."
- }
- $manifest | ConvertTo-Json -Depth 64 | Set-Content -LiteralPath (Join-Path $stage "manifest.json") -Encoding UTF8
- $inventory = New-Object System.Collections.Generic.List[object]
- Get-ChildItem -LiteralPath $stage -Recurse -File | Sort-Object FullName | ForEach-Object {
- if ($_.Name -eq "sha256-inventory.json") {
- return
- }
- $inventory.Add((New-InventoryItem $_.FullName $stage)) | Out-Null
- }
- [ordered]@{
- schema = "j6-host-sensor-real-fan-ptc-debug921-package-sha256-inventory-v1"
- generated_at = (Get-Date).ToUniversalTime().ToString("o")
- self_hash_policy = "excluded_self_referential_file"
- inventory = $inventory
- } | ConvertTo-Json -Depth 32 | Set-Content -LiteralPath (Join-Path $stage "sha256-inventory.json") -Encoding UTF8
- $zipPath = Join-Path $out ($PackageName + ".zip")
- if (Test-Path -LiteralPath $zipPath) {
- if (-not $ForceOverwrite) {
- throw "Package zip already exists: $zipPath. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
- }
- Remove-Item -LiteralPath $zipPath -Force
- }
- $zipSidecar = $zipPath + ".sha256.txt"
- if (Test-Path -LiteralPath $zipSidecar) {
- if (-not $ForceOverwrite) {
- throw "Package zip sidecar already exists: $zipSidecar. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
- }
- Remove-Item -LiteralPath $zipSidecar -Force
- }
- Compress-Archive -Path (Join-Path $stage "*") -DestinationPath $zipPath -Force
- $zipSha = Get-Sha256 $zipPath
- Set-Content -LiteralPath $zipSidecar -Encoding ASCII -Value ("{0} {1}" -f $zipSha, (Split-Path -Leaf $zipPath))
- Write-Host "Wrote $stage"
- Write-Host "Wrote $zipPath"
- Write-Host ("SHA256 {0} {1}" -f $zipSha, $zipPath)
- exit 0
- }
- $bitstreamCopy = Copy-IntoPackage $Bitstream (Join-Path $stage "bitstreams")
- $tdReceiptCopy = Copy-IntoPackage $TdReceipt (Join-Path $stage "td-receipts")
- Copy-IntoPackage $collectorPath (Join-Path $stage "collector") | Out-Null
- Copy-IntoPackage $bmcReplayPath (Join-Path $stage "bmc-replay") | Out-Null
- Copy-IntoPackage $schemaPath (Join-Path $stage "schemas") | Out-Null
- Copy-IntoPackage $runbookPath (Join-Path $stage "docs") | Out-Null
- Copy-IntoPackage $pinInventoryPath (Join-Path $stage "config") | Out-Null
- $bitName = Split-Path -Leaf $bitstreamCopy
- $tdName = Split-Path -Leaf $tdReceiptCopy
- Copy-Item -LiteralPath $bitstreamCopy -Destination (Join-Path $stage $ShortBitName) -Force
- Copy-Item -LiteralPath $tdReceiptCopy -Destination (Join-Path $stage $ShortTdName) -Force
- $shortcut = @'
- param(
- [string]$HostPort = "",
- [string]$DebugPort = "",
- [int]$DurationSeconds = 180,
- [string]$OutputDir = ".\evidence-com8-host-com7-debug",
- [ValidateSet("temp-uart-ptc-remap", "debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")]
- [string]$Profile = "temp-uart-ptc-remap",
- [string]$Bitstream = ".\j6tmp.bit",
- [string]$TdReceipt = ".\td.json",
- [int]$JtagSpeedHz = 200000,
- [object]$BoardPowerPresentBeforeProgram = $true,
- [switch]$SelfTest
- )
- $ErrorActionPreference = "Stop"
- $packageRoot = $PSScriptRoot
- $collector = Join-Path $packageRoot "collector\collect-j6-host-sensor-real-fan-ptc.ps1"
- $bitstreamPath = if ([System.IO.Path]::IsPathRooted($Bitstream)) { $Bitstream } else { Join-Path $packageRoot $Bitstream }
- $tdReceiptPath = if ([System.IO.Path]::IsPathRooted($TdReceipt)) { $TdReceipt } else { Join-Path $packageRoot $TdReceipt }
- $collectorProfile = if ($Profile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")) { "temp-uart-ptc-remap" } else { $Profile }
- $argsList = @(
- "-NoProfile",
- "-ExecutionPolicy", "Bypass",
- "-File", $collector
- )
- if ($SelfTest) {
- $argsList += "-SelfTest"
- } else {
- $argsList += @(
- "-HostPort", $HostPort,
- "-DebugPort", $DebugPort,
- "-DurationSeconds", $DurationSeconds,
- "-OutputDir", $OutputDir,
- "-Profile", $collectorProfile,
- "-Bitstream", $bitstreamPath,
- "-TdReceipt", $tdReceiptPath,
- "-JtagSpeedHz", $JtagSpeedHz,
- "-BoardPowerPresentBeforeProgram", $BoardPowerPresentBeforeProgram
- )
- }
- & "$PSHOME\powershell.exe" @argsList
- if ($LASTEXITCODE -ne 0) {
- exit $LASTEXITCODE
- }
- '@
- Set-Content -LiteralPath (Join-Path $stage "collect.ps1") -Encoding UTF8 -Value $shortcut
- $captureBmc = @'
- param(
- [ValidatePattern('^COM[0-9]+$')]
- [string]$BmcCapturePort = "",
- [string]$Input = ".\bmc-capture.txt",
- [string]$Payload = ".\bmc-replay-payload.json",
- [int]$Seq = 1,
- [int]$TimeoutSeconds = 3
- )
- $ErrorActionPreference = "Stop"
- $packageRoot = $PSScriptRoot
- $helper = Join-Path $packageRoot "bmc-replay\bmc_replay_uart.py"
- $inputPath = if ([System.IO.Path]::IsPathRooted($Input)) { $Input } else { Join-Path $packageRoot $Input }
- $payloadPath = if ([System.IO.Path]::IsPathRooted($Payload)) { $Payload } else { Join-Path $packageRoot $Payload }
- if (-not [string]::IsNullOrWhiteSpace($BmcCapturePort)) {
- $serial = New-Object System.IO.Ports.SerialPort
- $serial.PortName = $BmcCapturePort
- $serial.BaudRate = 115200
- $serial.DataBits = 8
- $serial.Parity = [System.IO.Ports.Parity]::None
- $serial.StopBits = [System.IO.Ports.StopBits]::One
- $serial.Handshake = [System.IO.Ports.Handshake]::None
- $serial.DtrEnable = $false
- $serial.RtsEnable = $false
- $serial.ReadTimeout = 50
- $serial.WriteTimeout = 1000
- $rawCommand = "ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03`n"
- $chunks = New-Object System.Collections.Generic.List[byte]
- try {
- $serial.Open()
- $bytes = [System.Text.Encoding]::ASCII.GetBytes($rawCommand)
- $serial.Write($bytes, 0, $bytes.Length)
- $deadline = (Get-Date).ToUniversalTime().AddSeconds($TimeoutSeconds)
- while ((Get-Date).ToUniversalTime() -lt $deadline) {
- try {
- $value = $serial.ReadByte()
- if ($value -ge 0) {
- $chunks.Add([byte]$value) | Out-Null
- }
- } catch [System.TimeoutException] {
- Start-Sleep -Milliseconds 10
- }
- }
- } finally {
- if ($serial.IsOpen) {
- $serial.Close()
- }
- }
- $text = [System.Text.Encoding]::ASCII.GetString($chunks.ToArray())
- if ([string]::IsNullOrWhiteSpace($text)) {
- throw "No BMC capture text received from $BmcCapturePort"
- }
- Set-Content -LiteralPath $inputPath -Encoding ASCII -Value $text
- }
- & python $helper normalize-capture --input $inputPath --payload $payloadPath --seq $Seq --json
- if ($LASTEXITCODE -ne 0) {
- exit $LASTEXITCODE
- }
- '@
- Set-Content -LiteralPath (Join-Path $stage "capture-bmc.ps1") -Encoding UTF8 -Value $captureBmc
- $examplePayload = [ordered]@{
- schema = "j6-bmc-replay-payload-v1"
- status = "debug_example_only"
- source = "synthetic_example"
- bmc_source = "example_payload_not_real_bmc_capture"
- live_bmc_link_status = "not_used"
- replay_mode = "poll_response"
- seq = 0
- poll_text = "ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03"
- poll_command_text = "ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03`n"
- 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"
- reply_sha256 = ""
- byte_count = 48
- valid_count = 24
- missing_count = 0
- safety = [ordered]@{
- unsolicited_reply_attempted = $false
- driver_install_attempted = $false
- programs_nonvolatile = $false
- }
- authority_boundary = "Synthetic example payload for temporary BMC replay wiring debug only. It is not real BMC evidence."
- }
- $examplePayload.reply_sha256 = Get-StringSha256 $examplePayload.reply_text
- $examplePayload | ConvertTo-Json -Depth 16 | Set-Content -LiteralPath (Join-Path $stage "bmc-replay-payload.example.json") -Encoding UTF8
- $replayBmc = @'
- param(
- [ValidatePattern('^COM[0-9]+$')]
- [string]$BmcReplayPort = "COM9",
- [string]$Payload = ".\bmc-replay-payload.json",
- [int]$Iterations = 0,
- [int]$TimeoutSeconds = 0,
- [switch]$SelfTest
- )
- $ErrorActionPreference = "Stop"
- $packageRoot = $PSScriptRoot
- $payloadPath = if ([System.IO.Path]::IsPathRooted($Payload)) { $Payload } else { Join-Path $packageRoot $Payload }
- function Read-Payload([string]$Path) {
- if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
- throw "Payload file not found: $Path"
- }
- $payload = Get-Content -LiteralPath $Path -Raw | ConvertFrom-Json
- if ([string]::IsNullOrWhiteSpace([string]$payload.reply_text)) {
- throw "Payload missing reply_text"
- }
- $pollText = [string]$payload.poll_command_text
- if ([string]::IsNullOrWhiteSpace($pollText)) {
- $pollText = [string]$payload.poll_text
- if (-not $pollText.EndsWith("`n")) {
- $pollText = $pollText + "`n"
- }
- }
- return [ordered]@{
- poll = $pollText
- reply = [string]$payload.reply_text
- sha256 = [string]$payload.reply_sha256
- }
- }
- function Invoke-ReplayCore($Endpoint, [string]$PollText, [string]$ReplyText, [int]$MaxIterations, [int]$MaxSeconds) {
- $poll = [System.Text.Encoding]::ASCII.GetBytes($PollText)
- $reply = [System.Text.Encoding]::ASCII.GetBytes($ReplyText)
- $window = New-Object System.Collections.Generic.List[byte]
- $matched = 0
- $deadline = if ($MaxSeconds -gt 0) { (Get-Date).ToUniversalTime().AddSeconds($MaxSeconds) } else { [DateTime]::MaxValue }
- while ($matched -lt $MaxIterations -or $MaxIterations -eq 0) {
- if ((Get-Date).ToUniversalTime() -gt $deadline) {
- break
- }
- $value = $Endpoint.ReadByte()
- if ($value -lt 0) {
- Start-Sleep -Milliseconds 2
- continue
- }
- $window.Add([byte]$value) | Out-Null
- $limit = [Math]::Max(4096, $poll.Length * 2)
- while ($window.Count -gt $limit) {
- $window.RemoveAt(0)
- }
- if ($window.Count -ge $poll.Length) {
- $match = $true
- for ($i = 0; $i -lt $poll.Length; $i++) {
- if ($window[$window.Count - $poll.Length + $i] -ne $poll[$i]) {
- $match = $false
- break
- }
- }
- if ($match) {
- $Endpoint.Write($reply, 0, $reply.Length)
- $matched += 1
- $window.Clear()
- Write-Host ("replay_reply_count={0}" -f $matched)
- }
- }
- }
- return [ordered]@{
- status = if ($matched -gt 0) { "pass" } else { "blocked_waiting_for_cpld_poll" }
- matched_poll_count = $matched
- reply_count = $matched
- unsolicited_reply_attempted = $false
- }
- }
- if ($SelfTest) {
- $tmp = Join-Path $env:TEMP ("j6-bmc-replay-selftest-" + [Guid]::NewGuid().ToString("N") + ".json")
- try {
- $sample = [ordered]@{
- 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"
- reply_sha256 = ""
- poll_command_text = "ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03`n"
- }
- $sample | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $tmp -Encoding UTF8
- $p = Read-Payload $tmp
- if (-not $p.poll.Contains("ipmitool raw")) { throw "poll selftest failed" }
- if (-not $p.reply.EndsWith("`n")) { throw "reply selftest failed" }
- Write-Host "selftest=pass"
- exit 0
- } finally {
- if (Test-Path -LiteralPath $tmp) {
- Remove-Item -LiteralPath $tmp -Force
- }
- }
- }
- $replayPayload = Read-Payload $payloadPath
- $serial = New-Object System.IO.Ports.SerialPort
- $serial.PortName = $BmcReplayPort
- $serial.BaudRate = 115200
- $serial.DataBits = 8
- $serial.Parity = [System.IO.Ports.Parity]::None
- $serial.StopBits = [System.IO.Ports.StopBits]::One
- $serial.Handshake = [System.IO.Ports.Handshake]::None
- $serial.DtrEnable = $false
- $serial.RtsEnable = $false
- $serial.ReadTimeout = 25
- $serial.WriteTimeout = 1000
- try {
- $serial.Open()
- Write-Host "Ready to replay BMC payload on $BmcReplayPort from $payloadPath"
- Write-Host "Safety: reply only after CPLD poll; no dependency setup, no COM enumeration, no device programming."
- $receipt = Invoke-ReplayCore $serial $replayPayload.poll $replayPayload.reply $Iterations $TimeoutSeconds
- $receipt | ConvertTo-Json -Depth 8
- } finally {
- if ($serial.IsOpen) {
- $serial.Close()
- }
- }
- '@
- Set-Content -LiteralPath (Join-Path $stage "replay-bmc.ps1") -Encoding UTF8 -Value $replayBmc
- $template = @'
- & "$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
- '@
- $template = $template.Replace("__PROFILE__", $Profile)
- Set-Content -LiteralPath (Join-Path $stage "commands\collect-template.ps1") -Encoding UTF8 -Value $template
- Set-Content -LiteralPath (Join-Path $stage "START-HERE.zh-CN.md") -Encoding UTF8 -Value (New-StartHereText $Profile $bitName $tdName $ShortBitName $ShortTdName)
- $hostControlCommands = @(
- "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",
- "GET SENSOR",
- "GET SENSOR",
- "SET PID DISABLE",
- "DISABLE"
- )
- $pinMap = New-PinMap $Profile
- $manifest = [ordered]@{
- schema = "j6-host-sensor-real-fan-ptc-debug921-package-manifest-v1"
- status = "pass"
- generated_at = (Get-Date).ToUniversalTime().ToString("o")
- package_name = $PackageName
- diagnostic_scope = "host_sensor_real_fan_ptc_debug921"
- pin_profile = $Profile
- programming_mode = "PROGRAM_SRAM"
- jtag_programming = [ordered]@{
- program_mode = "PROGRAM_SRAM"
- jtag_speed_hz = 200000
- board_power_present_before_program = $true
- tooling = "manual BitWriter/TD GUI"
- cli_programming_supported = $false
- cli_speed_mapping_proven = $false
- }
- bitstream = [ordered]@{ path = $ShortBitName; sha256 = Get-Sha256 (Join-Path $stage $ShortBitName) }
- td_receipt = [ordered]@{ path = $ShortTdName; sha256 = Get-Sha256 (Join-Path $stage $ShortTdName) }
- short_path_aliases = [ordered]@{
- bitstream = [ordered]@{
- path = $ShortBitName
- source = "bitstreams/$bitName"
- sha256 = Get-Sha256 (Join-Path $stage $ShortBitName)
- }
- td_receipt = [ordered]@{
- path = $ShortTdName
- source = "td-receipts/$tdName"
- sha256 = Get-Sha256 (Join-Path $stage $ShortTdName)
- }
- }
- collector = [ordered]@{
- path = "collector/collect-j6-host-sensor-real-fan-ptc.ps1"
- shortcut = "collect.ps1"
- user_profile_argument = $Profile
- profile_argument = $Profile
- collector_protocol_profile = if ($Profile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")) { "temp-uart-ptc-remap" } else { $Profile }
- ready_profile_string = "temp-uart-ptc-remap"
- }
- bmc_source = if ($Profile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")) { "pc_replay_from_real_bmc_capture" } else { "live_bmc_uart" }
- live_bmc_link_status = if ($Profile -in @("debug-photo-uart-bmc-replay", "formal-uart1-bmc-replay")) { "not_used" } else { "used" }
- bmc_replay = [ordered]@{
- helper = "bmc-replay/bmc_replay_uart.py"
- capture_shortcut = "capture-bmc.ps1"
- replay_shortcut = "replay-bmc.ps1"
- example_payload = "bmc-replay-payload.example.json"
- strict_payload_source = "capture-bmc.ps1 normalized real BMC capture"
- example_payload_authority = "debug fallback only; not real BMC evidence"
- port_argument = "BmcReplayPort"
- default_port = "COM9"
- mode = "pc_replay_from_real_bmc_capture"
- unsolicited_reply_attempted = $false
- }
- host_control_commands = $hostControlCommands
- startup_preflight = [ordered]@{
- expected_artifact = "startup-preflight.json"
- ready_line = "READY profile=temp-uart-ptc-remap seq=00000000"
- j6ready_line = "J6READY profile=temp-uart-ptc-remap"
- epoch_locked_required = $true
- formal_ack_count = 12
- }
- tail_drain = [ordered]@{
- expected_manifest_field = "debug_tail"
- expected_stream_field = "tail"
- purpose = "Close the DebugPort capture window so post-J6STAT complete J6RAW tail is attributed instead of misreported as frame loss."
- }
- pin_map = $pinMap
- real_fan_ptc_hardware_status = "not_run"
- 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." }
- 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."
- 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."
- }
- $manifestPath = Join-Path $stage "manifest.json"
- $manifest | ConvertTo-Json -Depth 64 | Set-Content -LiteralPath $manifestPath -Encoding UTF8
- $inventory = New-Object System.Collections.Generic.List[object]
- Get-ChildItem -LiteralPath $stage -Recurse -File | Sort-Object FullName | ForEach-Object {
- if ($_.Name -eq "sha256-inventory.json") {
- return
- }
- $inventory.Add((New-InventoryItem $_.FullName $stage)) | Out-Null
- }
- [ordered]@{
- schema = "j6-host-sensor-real-fan-ptc-debug921-package-sha256-inventory-v1"
- generated_at = (Get-Date).ToUniversalTime().ToString("o")
- self_hash_policy = "excluded_self_referential_file"
- inventory = $inventory
- } | ConvertTo-Json -Depth 32 | Set-Content -LiteralPath (Join-Path $stage "sha256-inventory.json") -Encoding UTF8
- $zipPath = Join-Path $out ($PackageName + ".zip")
- if (Test-Path -LiteralPath $zipPath) {
- if (-not $ForceOverwrite) {
- throw "Package zip already exists: $zipPath. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
- }
- Remove-Item -LiteralPath $zipPath -Force
- }
- $zipSidecar = $zipPath + ".sha256.txt"
- if (Test-Path -LiteralPath $zipSidecar) {
- if (-not $ForceOverwrite) {
- throw "Package zip sidecar already exists: $zipSidecar. Move it aside, choose a different -PackageName, or pass -ForceOverwrite."
- }
- Remove-Item -LiteralPath $zipSidecar -Force
- }
- Compress-Archive -Path (Join-Path $stage "*") -DestinationPath $zipPath -Force
- $zipSha = Get-Sha256 $zipPath
- Set-Content -LiteralPath $zipSidecar -Encoding ASCII -Value ("{0} {1}" -f $zipSha, (Split-Path -Leaf $zipPath))
- Write-Host "Wrote $stage"
- Write-Host "Wrote $zipPath"
- Write-Host ("SHA256 {0} {1}" -f $zipSha, $zipPath)
|