Sfoglia il codice sorgente

Fix temp evidence parsing and raw replay

Codex 5 mesi fa
parent
commit
f173835cf3

+ 4 - 5
docs/j6-host-sensor-real-fan-ptc-debug921-runbook.zh-CN.md

@@ -24,10 +24,9 @@
 
 
 ## 执行顺序
 ## 执行顺序
 
 
-1. 在 TD/ChipWatcher 中只执行 `PROGRAM_SRAM`,选择包内 `bitstreams/*.bit`。
-2. 确认 SRAM 下载完成后,再在包根目录打开 PowerShell。
-3. 执行包内 `commands/collect-template.ps1`,或复制 `START-HERE.zh-CN.md` 首页中的命令。
-4. 把生成的 evidence 目录回传分析。
+1. 先在包根目录打开 PowerShell,执行包内 `commands/collect-template.ps1`,或复制 `START-HERE.zh-CN.md` 首页中的 collector 命令。
+2. collector 打开 COM8/COM7 并开始等待后,再在 TD/ChipWatcher 中只执行 `PROGRAM_SRAM`,选择包内 `bitstreams/*.bit`。
+3. 等待 collector 自动完成 180 秒采集,把生成的 evidence 目录回传分析。
 
 
 不要执行 `PROGRAM_FLASH`、`ERASE_FLASH`、`PROGRAM_SPIBIN` 或 `DIRECT_FLASH_WRITE`。
 不要执行 `PROGRAM_FLASH`、`ERASE_FLASH`、`PROGRAM_SPIBIN` 或 `DIRECT_FLASH_WRITE`。
 
 
@@ -35,7 +34,7 @@
 
 
 HostPort 使用 1-based 两位编号,只接受 `PTC01..PTC24` 和 `FAN01..FAN04`。旧的 `PTC00`、`FAN00`、`FAN05`、`FAN06` 必须拒绝。
 HostPort 使用 1-based 两位编号,只接受 `PTC01..PTC24` 和 `FAN01..FAN04`。旧的 `PTC00`、`FAN00`、`FAN05`、`FAN06` 必须拒绝。
 
 
-collector 会先做非正式启动同步:等待 HostPort `READY profile=temp-uart-ptc-remap seq=00000000` 和 DebugPort `J6READY ...`,并最多发送非正式 `GET STATUS`。这些内容只写入 `startup-preflight.json`,不计入正式命令序列。
+collector 会先做非正式启动同步:等待 HostPort `READY profile=temp-uart-ptc-remap seq=00000000` 和 DebugPort `J6READY ...`,并最多发送非正式 `GET STATUS`。这些内容只写入 `startup-preflight.json`,不计入正式命令序列。执行顺序必须是 collector first, then PROGRAM_SRAM;否则可能错过上电第一帧 READY/J6READY。
 
 
 正式序列固定为:
 正式序列固定为:
 
 

+ 25 - 7
tests/unit/test_remote_scripts.py

@@ -334,7 +334,7 @@ if ($rawReplayArray.Length -ne 0) {{
             self.assertTrue(out_path.exists())
             self.assertTrue(out_path.exists())
             self.assertEqual(out_path.stat().st_size, 0)
             self.assertEqual(out_path.stat().st_size, 0)
 
 
-    def test_collect_j6_host_sensor_real_fan_ptc_parses_two_digit_hex_fields_as_int64(self) -> None:
+    def test_collect_j6_host_sensor_real_fan_ptc_parses_hex_fields_without_losing_payload_width(self) -> None:
         powershell = shutil.which("powershell")
         powershell = shutil.which("powershell")
         if powershell is None:
         if powershell is None:
             self.skipTest("PowerShell is not available")
             self.skipTest("PowerShell is not available")
@@ -343,7 +343,9 @@ if ($rawReplayArray.Length -ne 0) {{
         script = script_path.read_text(encoding="utf-8")
         script = script_path.read_text(encoding="utf-8")
         helper_start = script.index("function Convert-TokenValue")
         helper_start = script.index("function Convert-TokenValue")
         helper_end = script.index("function Convert-BytesToEscapedText")
         helper_end = script.index("function Convert-BytesToEscapedText")
-        helpers = script[helper_start:helper_end]
+        replay_helper_start = script.index("function Convert-HexToBytes")
+        replay_helper_end = script.index("function Get-LastFieldOrDefault")
+        helpers = script[helper_start:helper_end] + script[replay_helper_start:replay_helper_end]
 
 
         with tempfile.TemporaryDirectory() as tmp:
         with tempfile.TemporaryDirectory() as tmp:
             probe_path = Path(tmp) / "probe.ps1"
             probe_path = Path(tmp) / "probe.ps1"
@@ -353,9 +355,10 @@ if ($rawReplayArray.Length -ne 0) {{
 $events = New-Object System.Collections.Generic.List[object]
 $events = New-Object System.Collections.Generic.List[object]
 $events.Add((Convert-FrameLine "J6PWM seq=0000000A src=hm pid=disabled timeout=1 ptc01=00 ptc24=00 fan01=1E fan04=1E" @("J6PWM"))) | Out-Null
 $events.Add((Convert-FrameLine "J6PWM seq=0000000A src=hm pid=disabled timeout=1 ptc01=00 ptc24=00 fan01=1E fan04=1E" @("J6PWM"))) | Out-Null
 $events.Add((Convert-FrameLine "J6TEMP seq=00000003 status=valid valid=1E missing=00 fault=0 host_report_drop=00000000" @("J6TEMP"))) | Out-Null
 $events.Add((Convert-FrameLine "J6TEMP seq=00000003 status=valid valid=1E missing=00 fault=0 host_report_drop=00000000" @("J6TEMP"))) | Out-Null
-$events.Add((Convert-FrameLine "J6RAW seq=00000001 off=00000000 len=30 sum=00FF data=FFFFFFFF" @("J6RAW"))) | Out-Null
+$events.Add((Convert-FrameLine "J6RAW seq=00000001 off=00000000 len=02 sum=0031 data=0031" @("J6RAW"))) | Out-Null
 $events.Add((Convert-FrameLine "J6RAW s=002A o=00000100 l=04 u=000A d=01020304" @("J6RAW"))) | Out-Null
 $events.Add((Convert-FrameLine "J6RAW s=002A o=00000100 l=04 u=000A d=01020304" @("J6RAW"))) | Out-Null
 $events.Add((Convert-FrameLine "J6EVT s=06 cmd=PID_E c=01 p=000 ok=1 e=0 to=0" @("J6EVT"))) | Out-Null
 $events.Add((Convert-FrameLine "J6EVT s=06 cmd=PID_E c=01 p=000 ok=1 e=0 to=0" @("J6EVT"))) | Out-Null
+$events.Add((Convert-FrameLine "DIMM i=10 t=00 m=1" @("DIMM"))) | Out-Null
 
 
 foreach ($probe in @(
 foreach ($probe in @(
     @($events[0].fields.fan01, "fan01"),
     @($events[0].fields.fan01, "fan01"),
@@ -380,16 +383,22 @@ if ([int64]$events[0].fields.fan01 -ne 30) { throw "fan01 was $($events[0].field
 if ([int64]$events[0].fields.timeout -ne 1) { throw "timeout was $($events[0].fields.timeout)" }
 if ([int64]$events[0].fields.timeout -ne 1) { throw "timeout was $($events[0].fields.timeout)" }
 if ([int64]$events[1].fields.valid -ne 30) { throw "valid was $($events[1].fields.valid)" }
 if ([int64]$events[1].fields.valid -ne 30) { throw "valid was $($events[1].fields.valid)" }
 if ([int64]$events[1].fields.missing -ne 0) { throw "missing was $($events[1].fields.missing)" }
 if ([int64]$events[1].fields.missing -ne 0) { throw "missing was $($events[1].fields.missing)" }
-if ([int64]$events[2].fields.len -ne 48) { throw "len was $($events[2].fields.len)" }
-if ([int64]$events[2].fields.sum -ne 255) { throw "sum was $($events[2].fields.sum)" }
+if ([int64]$events[2].fields.len -ne 2) { throw "len was $($events[2].fields.len)" }
+if ([int64]$events[2].fields.sum -ne 49) { throw "sum was $($events[2].fields.sum)" }
 if ([int64]$events[3].fields.seq -ne 42) { throw "compact seq was $($events[3].fields.seq)" }
 if ([int64]$events[3].fields.seq -ne 42) { throw "compact seq was $($events[3].fields.seq)" }
 if ([int64]$events[3].fields.off -ne 256) { throw "compact off was $($events[3].fields.off)" }
 if ([int64]$events[3].fields.off -ne 256) { throw "compact off was $($events[3].fields.off)" }
 if ([int64]$events[3].fields.len -ne 4) { throw "compact len was $($events[3].fields.len)" }
 if ([int64]$events[3].fields.len -ne 4) { throw "compact len was $($events[3].fields.len)" }
 if ([int64]$events[3].fields.sum -ne 10) { throw "compact sum was $($events[3].fields.sum)" }
 if ([int64]$events[3].fields.sum -ne 10) { throw "compact sum was $($events[3].fields.sum)" }
+if ($events[2].fields.data.GetType().FullName -ne "System.String") { throw "data parsed as $($events[2].fields.data.GetType().FullName)" }
+if ($events[2].fields.data -ne "0031") { throw "data was $($events[2].fields.data)" }
 if ($events[3].fields.data -ne "01020304") { throw "compact data was $($events[3].fields.data)" }
 if ($events[3].fields.data -ne "01020304") { throw "compact data was $($events[3].fields.data)" }
 if ([int64]$events[4].fields.ch -ne 1) { throw "compact ch was $($events[4].fields.ch)" }
 if ([int64]$events[4].fields.ch -ne 1) { throw "compact ch was $($events[4].fields.ch)" }
 if ([int64]$events[4].fields.pct -ne 0) { throw "compact pct was $($events[4].fields.pct)" }
 if ([int64]$events[4].fields.pct -ne 0) { throw "compact pct was $($events[4].fields.pct)" }
 if ([int64]$events[4].fields.err -ne 0) { throw "compact err was $($events[4].fields.err)" }
 if ([int64]$events[4].fields.err -ne 0) { throw "compact err was $($events[4].fields.err)" }
+if ([int64]$events[5].fields.id -ne 16) { throw "dimm id was $($events[5].fields.id)" }
+$replay = New-BmcRawReplay $events
+$replayHex = (($replay | ForEach-Object { $_.ToString("X2") }) -join "")
+if ($replayHex -ne "003101020304") { throw "replay was $replayHex" }
 """,
 """,
                 encoding="utf-8",
                 encoding="utf-8",
             )
             )
@@ -464,6 +473,8 @@ if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.
             "j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2",
             "j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2",
             "startup-preflight.json",
             "startup-preflight.json",
             "READY profile=temp-uart-ptc-remap",
             "READY profile=temp-uart-ptc-remap",
+            "collector first, then PROGRAM_SRAM",
+            "ForceOverwrite",
             "SET PTC 01 10",
             "SET PTC 01 10",
             "SET PTC 24 20",
             "SET PTC 24 20",
             "SET FAN 01 40",
             "SET FAN 01 40",
@@ -558,6 +569,8 @@ if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.
                     self.assertTrue((Path(tmp) / f"{package_name}.zip.sha256.txt").is_file())
                     self.assertTrue((Path(tmp) / f"{package_name}.zip.sha256.txt").is_file())
                     start_here = (stage / "START-HERE.zh-CN.md").read_text(encoding="utf-8-sig")
                     start_here = (stage / "START-HERE.zh-CN.md").read_text(encoding="utf-8-sig")
                     self.assertIn("PROGRAM_SRAM", start_here)
                     self.assertIn("PROGRAM_SRAM", start_here)
+                    self.assertIn("先启动 collector", start_here)
+                    self.assertIn("collector first, then PROGRAM_SRAM", start_here)
                     self.assertIn(f"-Profile {profile}", start_here)
                     self.assertIn(f"-Profile {profile}", start_here)
                     self.assertIn(f".\\bitstreams\\{bitstream.name}", start_here)
                     self.assertIn(f".\\bitstreams\\{bitstream.name}", start_here)
                     self.assertIn(f".\\td-receipts\\{td_receipt.name}", start_here)
                     self.assertIn(f".\\td-receipts\\{td_receipt.name}", start_here)
@@ -565,6 +578,8 @@ if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.
                     self.assertIn("-HostPort COM8 -DebugPort COM7", start_here)
                     self.assertIn("-HostPort COM8 -DebugPort COM7", start_here)
                     self.assertNotIn("Set-ExecutionPolicy", start_here)
                     self.assertNotIn("Set-ExecutionPolicy", start_here)
                     self.assertNotIn("-AssumeManualSramProgrammed", start_here)
                     self.assertNotIn("-AssumeManualSramProgrammed", start_here)
+                    self.assertNotIn("先手动刷 SRAM", start_here)
+                    self.assertNotIn("刷完 SRAM 后采集", start_here)
                     collect_template = (stage / "commands" / "collect-template.ps1").read_text(
                     collect_template = (stage / "commands" / "collect-template.ps1").read_text(
                         encoding="utf-8-sig"
                         encoding="utf-8-sig"
                     )
                     )
@@ -602,6 +617,7 @@ if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.
             "START-HERE.zh-CN.md",
             "START-HERE.zh-CN.md",
             "temp-uart-ptc-remap",
             "temp-uart-ptc-remap",
             "PROGRAM_SRAM",
             "PROGRAM_SRAM",
+            "collector first, then PROGRAM_SRAM",
             "COM8",
             "COM8",
             "COM7",
             "COM7",
             "PTC03",
             "PTC03",
@@ -641,6 +657,8 @@ if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.
             "blocked_edit_required",
             "blocked_edit_required",
             "当前不要刷机",
             "当前不要刷机",
             "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force",
             "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force",
+            "先手动刷 SRAM",
+            "确认 SRAM 下载完成后",
             r".\commands\collect-com8-host-com7-debug.ps1",
             r".\commands\collect-com8-host-com7-debug.ps1",
             r"bitstreams\uart_rs232_j6_host_sensor_real_fan_ptc_debug921_primary.bit",
             r"bitstreams\uart_rs232_j6_host_sensor_real_fan_ptc_debug921_primary.bit",
             "collector/collect-j6-host-sensor-real-fan-ptc.ps1",
             "collector/collect-j6-host-sensor-real-fan-ptc.ps1",
@@ -649,7 +667,8 @@ if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.
             "SET FAN 05",
             "SET FAN 05",
             "SET FAN 06",
             "SET FAN 06",
             r".\collector\采集",
             r".\collector\采集",
-        ]:            self.assertNotIn(forbidden, runbook)
+        ]:
+            self.assertNotIn(forbidden, runbook)
 
 
     def test_j6_host_sensor_real_fan_ptc_schema_requires_sensor_pwm_pid_pinmap_and_debug_artifacts(self) -> None:
     def test_j6_host_sensor_real_fan_ptc_schema_requires_sensor_pwm_pid_pinmap_and_debug_artifacts(self) -> None:
         schema = json.loads(
         schema = json.loads(
@@ -687,4 +706,3 @@ if ($events[2].fields.cmd -ne "FANCH") { throw "ack cmd was $($events[2].fields.
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     unittest.main()
     unittest.main()
-

+ 18 - 0
tests/unit/test_uart_receipts.py

@@ -17,6 +17,7 @@ ROOT = Path(__file__).resolve().parents[2]
 sys.path.insert(0, str(ROOT / "tools"))
 sys.path.insert(0, str(ROOT / "tools"))
 
 
 from uart_receipts import (  # noqa: E402
 from uart_receipts import (  # noqa: E402
+    _host_sensor_row_fields,
     _parse_host_sensor_report_text,
     _parse_host_sensor_report_text,
     _parse_j6raw_frames,
     _parse_j6raw_frames,
     _parse_lossless_key_value_lines,
     _parse_lossless_key_value_lines,
@@ -1370,6 +1371,23 @@ class UartReceiptsTests(unittest.TestCase):
         self.assertEqual(parsed["samples"][0]["seq"], 3)
         self.assertEqual(parsed["samples"][0]["seq"], 3)
         self.assertEqual(parsed["samples"][0]["dimm_rows"][0]["seq"], 3)
         self.assertEqual(parsed["samples"][0]["dimm_rows"][0]["seq"], 3)
         self.assertEqual(parsed["samples"][0]["dimm_rows"][0]["temp"], 0x30)
         self.assertEqual(parsed["samples"][0]["dimm_rows"][0]["temp"], 0x30)
+        self.assertEqual(
+            sorted(row["id"] for row in parsed["samples"][0]["dimm_rows"]),
+            list(range(24)),
+        )
+
+    def test_host_sensor_sidecar_recovers_compact_hex_id_from_raw_line(self) -> None:
+        row = {
+            "raw": "DIMM i=10 t=00 m=1 ",
+            "fields": {"i": 10, "t": 0, "m": 1, "temp": 0, "missing": 1, "seq": 12},
+            "temp": 0,
+            "missing": 1,
+            "seq": 12,
+        }
+
+        fields = _host_sensor_row_fields(row)
+
+        self.assertEqual(fields["id"], 16)
 
 
     def test_j6raw_parser_accepts_compact_replay_fields(self) -> None:
     def test_j6raw_parser_accepts_compact_replay_fields(self) -> None:
         frames = _parse_j6raw_frames("J6RAW s=002A o=00000100 l=04 u=000A d=01020304\r\n")
         frames = _parse_j6raw_frames("J6RAW s=002A o=00000100 l=04 u=000A d=01020304\r\n")

+ 38 - 17
tools/package_j6_host_sensor_real_fan_ptc_debug921.ps1

@@ -7,7 +7,8 @@
     [Parameter(Mandatory = $true)]
     [Parameter(Mandatory = $true)]
     [string]$Bitstream,
     [string]$Bitstream,
     [Parameter(Mandatory = $true)]
     [Parameter(Mandatory = $true)]
-    [string]$TdReceipt
+    [string]$TdReceipt,
+    [switch]$ForceOverwrite
 )
 )
 
 
 $ErrorActionPreference = "Stop"
 $ErrorActionPreference = "Stop"
@@ -15,7 +16,7 @@ $ErrorActionPreference = "Stop"
 # Package profile:
 # Package profile:
 # temp-uart-ptc-remap -> j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2
 # temp-uart-ptc-remap -> j6-host-sensor-real-fan-ptc-temp-uart-ptc-remap-debug921-v2
 # The copied collector is tools\remote\collect-j6-host-sensor-real-fan-ptc.ps1.
 # The copied collector is tools\remote\collect-j6-host-sensor-real-fan-ptc.ps1.
-# The collector defaults to assuming the operator already ran PROGRAM_SRAM.
+# Start the collector first, then run manual PROGRAM_SRAM so READY/J6READY is captured.
 
 
 function Get-Sha256([string]$Path) {
 function Get-Sha256([string]$Path) {
     if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
     if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
@@ -92,19 +93,9 @@ function New-StartHereText([string]$SelectedProfile, [string]$BitName, [string]$
     return @"
     return @"
 # $title
 # $title
 
 
-## 1. 先手动刷 SRAM
+## 1. 先启动 collector
 
 
-在 TD/ChipWatcher 中只执行 `PROGRAM_SRAM`,选择下面这个 bitstream:
-
-~~~text
-bitstreams/$BitName
-~~~
-
-不要执行 `PROGRAM_FLASH`、`ERASE_FLASH`、`PROGRAM_SPIBIN` 或 `DIRECT_FLASH_WRITE`。
-
-## 2. 刷完 SRAM 后采集
-
-确认 SRAM 下载完成后,在本包根目录打开 PowerShell,复制执行下面这一条命令:
+在本包根目录打开 PowerShell,先复制执行下面这一条命令。collector 会先打开 COM8/COM7、等待 READY/J6READY,并把启动同步写入 `startup-preflight.json`。
 
 
 ~~~powershell
 ~~~powershell
 powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collector\collect-j6-host-sensor-real-fan-ptc.ps1 -HostPort COM8 -DebugPort COM7 -DurationSeconds 180 -OutputDir .\evidence-com8-host-com7-debug -Profile $SelectedProfile -Bitstream .\bitstreams\$BitName -TdReceipt .\td-receipts\$TdName
 powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collector\collect-j6-host-sensor-real-fan-ptc.ps1 -HostPort COM8 -DebugPort COM7 -DurationSeconds 180 -OutputDir .\evidence-com8-host-com7-debug -Profile $SelectedProfile -Bitstream .\bitstreams\$BitName -TdReceipt .\td-receipts\$TdName
@@ -116,6 +107,18 @@ powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\collector\collect-j6-h
 powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\commands\collect-template.ps1
 powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\commands\collect-template.ps1
 ~~~
 ~~~
 
 
+## 2. collector 启动后手动刷 SRAM
+
+collector 开始等待后,在 TD/ChipWatcher 中只执行 `PROGRAM_SRAM`,选择下面这个 bitstream:
+
+~~~text
+bitstreams/$BitName
+~~~
+
+不要执行 `PROGRAM_FLASH`、`ERASE_FLASH`、`PROGRAM_SPIBIN` 或 `DIRECT_FLASH_WRITE`。
+
+collector first, then PROGRAM_SRAM. 这样可以捕获上电第一帧 `READY/J6READY`,避免旧证据里的 preflight missing。
+
 ## 接线
 ## 接线
 
 
 $wiring
 $wiring
@@ -144,7 +147,15 @@ if ([string]::IsNullOrWhiteSpace($PackageName)) {
 
 
 $stage = Join-Path $out $PackageName
 $stage = Join-Path $out $PackageName
 if (Test-Path -LiteralPath $stage) {
 if (Test-Path -LiteralPath $stage) {
-    throw "Package staging directory already exists: $stage. Move it aside or choose a different -PackageName."
+    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")) {
 foreach ($dir in @("bitstreams", "td-receipts", "collector", "commands", "schemas", "docs", "config")) {
@@ -229,11 +240,21 @@ Get-ChildItem -LiteralPath $stage -Recurse -File | Sort-Object FullName | ForEac
 
 
 $zipPath = Join-Path $out ($PackageName + ".zip")
 $zipPath = Join-Path $out ($PackageName + ".zip")
 if (Test-Path -LiteralPath $zipPath) {
 if (Test-Path -LiteralPath $zipPath) {
-    throw "Package zip already exists: $zipPath. Move it aside or choose a different -PackageName."
+    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
 Compress-Archive -Path (Join-Path $stage "*") -DestinationPath $zipPath -Force
 $zipSha = Get-Sha256 $zipPath
 $zipSha = Get-Sha256 $zipPath
-Set-Content -LiteralPath ($zipPath + ".sha256.txt") -Encoding ASCII -Value ("{0}  {1}" -f $zipSha, (Split-Path -Leaf $zipPath))
+Set-Content -LiteralPath $zipSidecar -Encoding ASCII -Value ("{0}  {1}" -f $zipSha, (Split-Path -Leaf $zipPath))
 
 
 Write-Host "Wrote $stage"
 Write-Host "Wrote $stage"
 Write-Host "Wrote $zipPath"
 Write-Host "Wrote $zipPath"

+ 20 - 3
tools/remote/collect-j6-host-sensor-real-fan-ptc.ps1

@@ -160,11 +160,11 @@ function New-ArtifactRef([string]$Path, [string]$BaseDir) {
 }
 }
 
 
 function Convert-TokenValue([string]$Key, [string]$Raw) {
 function Convert-TokenValue([string]$Key, [string]$Raw) {
-    $stringKeys = @("cmd", "data", "text", "source", "status", "st", "src", "pwm", "pwm_source", "pid", "type", "ty")
+    $stringKeys = @("cmd", "data", "d", "text", "source", "status", "st", "src", "pwm", "pwm_source", "pid", "type", "ty")
     if ($stringKeys -contains $Key) {
     if ($stringKeys -contains $Key) {
         return $Raw
         return $Raw
     }
     }
-    $hexKeys = @("seq", "s", "id", "v", "m", "tp", "t", "tx", "rx", "drop", "off", "o", "len", "l", "sum", "u", "raw_in", "ri", "raw_out", "ro", "raw_drop", "rd", "host_report_drop", "hd", "fifo", "fifo_max", "bmc_berr", "be", "host_err", "he", "err", "e", "ch", "c", "pct", "p", "p0", "p23", "f0", "f5", "ptc01", "ptc24", "fan01", "fan04")
+    $hexKeys = @("seq", "s", "id", "i", "v", "m", "tp", "t", "tx", "rx", "drop", "off", "o", "len", "l", "sum", "u", "raw_in", "ri", "raw_out", "ro", "raw_drop", "rd", "host_report_drop", "hd", "fifo", "fifo_max", "bmc_berr", "be", "host_err", "he", "err", "e", "ch", "c", "pct", "p", "p0", "p23", "f0", "f5", "ptc01", "ptc24", "fan01", "fan04")
     if ($hexKeys -contains $Key) {
     if ($hexKeys -contains $Key) {
         if ($Raw -notmatch '^[0-9A-Fa-f]+$') {
         if ($Raw -notmatch '^[0-9A-Fa-f]+$') {
             return $Raw
             return $Raw
@@ -210,6 +210,7 @@ function Convert-FrameLine([string]$Line, [string[]]$Prefixes) {
             if (-not $fields.Contains("len") -and $fields.Contains("l")) { $fields["len"] = $fields["l"] }
             if (-not $fields.Contains("len") -and $fields.Contains("l")) { $fields["len"] = $fields["l"] }
             if (-not $fields.Contains("sum") -and $fields.Contains("u")) { $fields["sum"] = $fields["u"] }
             if (-not $fields.Contains("sum") -and $fields.Contains("u")) { $fields["sum"] = $fields["u"] }
             if (-not $fields.Contains("data") -and $fields.Contains("d")) { $fields["data"] = $fields["d"] }
             if (-not $fields.Contains("data") -and $fields.Contains("d")) { $fields["data"] = $fields["d"] }
+            if (-not $fields.Contains("id") -and $fields.Contains("i")) { $fields["id"] = $fields["i"] }
             if (-not $fields.Contains("temp") -and $fields.Contains("tp")) { $fields["temp"] = $fields["tp"] }
             if (-not $fields.Contains("temp") -and $fields.Contains("tp")) { $fields["temp"] = $fields["tp"] }
             if (-not $fields.Contains("temp") -and $fields.Contains("t")) { $fields["temp"] = $fields["t"] }
             if (-not $fields.Contains("temp") -and $fields.Contains("t")) { $fields["temp"] = $fields["t"] }
             if (-not $fields.Contains("bmc_berr") -and $fields.Contains("be")) { $fields["bmc_berr"] = $fields["be"] }
             if (-not $fields.Contains("bmc_berr") -and $fields.Contains("be")) { $fields["bmc_berr"] = $fields["be"] }
@@ -696,7 +697,23 @@ function New-BmcRawReplay([System.Collections.Generic.List[object]]$Events) {
         if (-not $event.fields.Contains("data")) {
         if (-not $event.fields.Contains("data")) {
             continue
             continue
         }
         }
-        $chunk = Convert-HexToBytes ([string]$event.fields.data)
+        $dataHex = [string]$event.fields.data
+        if ($dataHex -notmatch '^[0-9A-Fa-f]*$' -or (($dataHex.Length % 2) -ne 0)) {
+            throw "J6RAW data is not even-width hex: $dataHex"
+        }
+        $chunk = Convert-HexToBytes $dataHex
+        if ($event.fields.Contains("len") -and [int64]$event.fields.len -ne $chunk.Length) {
+            throw "J6RAW len mismatch: len=$($event.fields.len) bytes=$($chunk.Length) raw=$($event.raw)"
+        }
+        if ($event.fields.Contains("sum")) {
+            $actualSum = [int64]0
+            foreach ($byte in $chunk) {
+                $actualSum = ($actualSum + [int64]$byte) -band 0xFFFF
+            }
+            if ([int64]$event.fields.sum -ne $actualSum) {
+                throw "J6RAW checksum mismatch: sum=$($event.fields.sum) actual=$actualSum raw=$($event.raw)"
+            }
+        }
         foreach ($byte in $chunk) {
         foreach ($byte in $chunk) {
             $outBytes.Add($byte) | Out-Null
             $outBytes.Add($byte) | Out-Null
         }
         }

+ 38 - 1
tools/uart_receipts.py

@@ -545,6 +545,32 @@ def _safe_int(value: Any, *, default: int | None = None) -> int | None:
         return default
         return default
 
 
 
 
+def _safe_fixed_hex_int(value: Any, *, default: int | None = None) -> int | None:
+    try:
+        if isinstance(value, bool):
+            return int(value)
+        if isinstance(value, int):
+            return value
+        if isinstance(value, str):
+            token = value.strip()
+            if token.lower().startswith("0x"):
+                token = token[2:]
+            if re.fullmatch(r"[0-9A-Fa-f]+", token):
+                return int(token, 16)
+        return int(value)
+    except (TypeError, ValueError):
+        return default
+
+
+def _raw_field_token(raw: Any, key: str) -> str | None:
+    if not isinstance(raw, str):
+        return None
+    match = re.search(rf"(?:^|\s){re.escape(key)}=([^ \t\r\n]+)", raw)
+    if not match:
+        return None
+    return match.group(1).rstrip("\\r").rstrip("\\n")
+
+
 def _normalize_compact_alias_value(field: str, value: Any) -> Any:
 def _normalize_compact_alias_value(field: str, value: Any) -> Any:
     if not isinstance(value, str):
     if not isinstance(value, str):
         return value
         return value
@@ -1012,6 +1038,7 @@ LOSSLESS_HEX_FIELDS = {
     "seq",
     "seq",
     "cmd",
     "cmd",
     "id",
     "id",
+    "i",
     "s",
     "s",
     "v",
     "v",
     "m",
     "m",
@@ -1097,6 +1124,8 @@ def _parse_lossless_key_value_lines(text: str, prefix: str) -> list[dict[str, An
             fields["raw_out"] = fields["ro"]
             fields["raw_out"] = fields["ro"]
         if "seq" not in fields and "s" in fields:
         if "seq" not in fields and "s" in fields:
             fields["seq"] = fields["s"]
             fields["seq"] = fields["s"]
+        if "id" not in fields and "i" in fields:
+            fields["id"] = fields["i"]
         if "temp" not in fields and "tp" in fields:
         if "temp" not in fields and "tp" in fields:
             fields["temp"] = fields["tp"]
             fields["temp"] = fields["tp"]
         if "temp" not in fields and "t" in fields:
         if "temp" not in fields and "t" in fields:
@@ -1165,11 +1194,19 @@ def _host_sensor_row_fields(row: Any) -> dict[str, Any]:
         return {}
         return {}
     fields = row.get("fields") if isinstance(row.get("fields"), dict) else {}
     fields = row.get("fields") if isinstance(row.get("fields"), dict) else {}
     merged: dict[str, Any] = dict(fields)
     merged: dict[str, Any] = dict(fields)
-    for key in ("seq", "s", "id", "temp", "tp", "t", "missing", "miss", "status", "st", "raw", "fault"):
+    for key in ("seq", "s", "id", "i", "temp", "tp", "t", "missing", "miss", "status", "st", "raw", "fault"):
         if key in row and key not in merged:
         if key in row and key not in merged:
             merged[key] = row[key]
             merged[key] = row[key]
     if "seq" not in merged and "s" in merged:
     if "seq" not in merged and "s" in merged:
         merged["seq"] = merged["s"]
         merged["seq"] = merged["s"]
+    if "id" not in merged and "i" in merged:
+        raw_i = _raw_field_token(row.get("raw"), "i")
+        merged["id"] = _safe_fixed_hex_int(raw_i if raw_i is not None else merged["i"], default=merged["i"])
+    elif "id" in merged:
+        raw_id = _raw_field_token(row.get("raw"), "id")
+        normalized_id = _safe_fixed_hex_int(raw_id if raw_id is not None else merged["id"], default=None)
+        if normalized_id is not None:
+            merged["id"] = normalized_id
     if "temp" not in merged and "tp" in merged:
     if "temp" not in merged and "tp" in merged:
         merged["temp"] = merged["tp"]
         merged["temp"] = merged["tp"]
     if "temp" not in merged and "t" in merged:
     if "temp" not in merged and "t" in merged: