Просмотр исходного кода

test: close 6400 boot safety and locked GET evidence

root 3 месяцев назад
Родитель
Сommit
d08c74348a

+ 5 - 3
docs/architecture/6400-v1-design-lock.md

@@ -25,15 +25,17 @@ Status: FROZEN for this task after the five audits in `docs/audits/`. Changes re
 Frame: `A5 5A | TYPE | LENGTH | PAYLOAD | CRC_LOW | CRC_HIGH`. CRC-16/CCITT-FALSE covers TYPE, LENGTH, and payload. Invalid header, length, CRC, type, target, or timeout is silently discarded. There is no NACK, version, project ID, capability, sequence, transaction ID, timestamp, TLV, command queue, or parallel outstanding transaction.
 
 - `0x01 SET_TARGET`, payload length 1: `0` enters STOPPED; `20..70` atomically commits the global Celsius target; all other values are rejected. A legal commit returns `0x81 SET_TARGET_ACK`, zero payload. ACK means commit only.
-- `0x02 GET_SNAPSHOT`, zero payload: returns `0x82 SNAPSHOT_DATA`; DATA is the only reply.
+- `0x02 GET_SNAPSHOT`, zero payload: after the snapshot banks, epochs, and fixed fields are locked, returns an independent zero-payload `0x82 GET_SNAPSHOT_ACK`, then `0x42 SNAPSHOT_DATA` with the fixed 193-byte payload. The Host must process `WAIT_ACK` before `WAIT_DATA`; DATA never substitutes for ACK.
 - `0x03 SET_STIMULUS`, identification and sim-debug profiles only: duration 1..255 seconds, 24 PTC duties, 4 front duties, 4 rear duties, all 0..100; legal atomic commit returns zero-payload `0x83`. Production removes the decoder path at compile time.
 - The Host may retry idempotent SET_TARGET after an ACK timeout. HTH permits one outstanding transaction only.
 
+Every legal Host request receives its own ACK (`0x81`, `0x82`, or profile-gated `0x83`). SET ACK follows atomic commit. GET ACK follows snapshot locking and precedes DATA. The selected Host port and snapshot lock remain held until the final DATA CRC byte stop bit completes. Invalid requests remain silent drops; BMC framing is unchanged and has no ACK.
+
 The snapshot layout is generated from `contracts/6400-snapshot.yaml`, is fixed and under 200 bytes, and contains state/fault/target/source flags; BMC, CT, and control epochs and ages; 24 BMC raw pairs and valid bits; 27 CT raw values and valid bits; requested/applied PTC/front/rear duties; safety mask; lane faults; and global fault. TX locks bank IDs and streams offsets without copying the payload into flip-flops.
 
 ## Control sequence
 
-Reset values: target 70 C, PTC 0, front/rear fan 10, epochs/valid/integrators clear.
+Reset values: target 70 C, PTC 0, front/rear fan banks 10, epochs/valid/integrators clear. Physical fans remain on the full-speed boot request through bank initialization and one complete PWM boundary before 10% standby is exposed.
 
 1. `RESET_SAFE`: enforce safe outputs, then enter `WAIT_CT_VALID`.
 2. `WAIT_CT_VALID`: wait for a complete valid CT scan required by the channel map.
@@ -69,7 +71,7 @@ This proves only deterministic electrical override after a sampled condition. Ph
 
 ## PWM and storage
 
-- One global 0..99 phase, one 0..499 subcounter, one channel index, one synchronous duty read, one comparator, one 32-bit `next_bitmap`, and one 32-bit `active_bitmap`.
+- PTC and FAN frequency/phase-clock values are independent generated parameters. The V1 contract sets both to 500 Hz and selects the resource-minimal equal-frequency backend: one global 0..99 phase, one 0..499 subcounter, one channel index, one synchronous duty read, one comparator, one 32-bit `next_bitmap`, and one 32-bit `active_bitmap`. An unequal future contract must select a dual-carrier backend and cannot silently inherit the PTC frequency.
 - During each phase, scan all 32 requested/applied duties into `next_bitmap`. At the phase boundary atomically assign `active_bitmap <= next_bitmap`.
 - `duty=0` is always off; `100` always on; 1..99 are exact phase counts. Compile-time polarity masks drive physical pins.
 - BMC, CT, requested duties, snapshot view, and applicable parameters use inactive-bank writes plus a single bank-pointer flip. No large active-array copy is allowed.

+ 51 - 0
docs/electrical/rear-fan-evidence-lock.md

@@ -0,0 +1,51 @@
+# 6400 V1.1 front/rear fan electrical evidence lock
+
+Status: board-level mapping CONFIRMED; assembled pull-ups, exact fan model, and system harness order remain unresolved.
+
+## Evidence sources
+
+- Schematic: `reference/original/schematics/FCB_FPGA+MCU0611.pdf`, SHA-256 `CAABC66444C7B9D59682155F5971C3EB635033A846E478930700237B8104FC64` in the V1.1 board audit checkout. Physical PDF page equals title-block Sheet: page 3 CPLD balls, page 7 front fan stages, page 8 rear connectors and optional pull-ups, page 10 functional-net to bank-net continuity.
+- BRD: `reference/original/board/FCB_FPGA_MCU_V1.1_20260625/FCB_FPGA+MCU_V1.1_20260625.brd`, SHA-256 `DB02938F7943B2AE532AA18208F61588364D32A70A0CC72F74B4A94AAAB7E258`.
+- Derived annotation: `config/board_viewer_annotations.fcb_fpga_mcu_v1_1.json` in the V1.1 board audit checkout.
+- User-confirmed airflow roles: CON25/8/24/26 are intake; CON64/66/62/60 are exhaust. A matching 6400 assembly/harness drawing was not found, so physical board connectivity is confirmed while system-level lane/harness order remains `UNRESOLVED_USER_CONFIRMED`.
+- The 8000 V2 drawing with CON31/32/33/34/35/68 is a different harness and is explicitly excluded from this 6400 mapping.
+
+## Locked output vector and board path
+
+The sole production vector order is `front0..front3, rear0..rear3`, corresponding to logical output indices 24..31. Therefore `FAN_BOARD_INVERT_MASK=8'h0F`; `8'h55` belongs only to an obsolete interleaved representation and is forbidden here.
+
+| Output | Role | Schematic page | Connector pin | Net | Board stage | FPGA ball | Board inversion | Evidence level | Unresolved |
+| --- | --- | ---: | --- | --- | --- | --- | --- | --- | --- |
+| front0 | intake L0 | 3, 7, 10 | CON25.7 | FAN_PWM3 | Q101 | B1 | yes | board confirmed | harness lane only user-confirmed |
+| front1 | intake L1 | 3, 7, 10 | CON8.7 | FAN_PWM1 | Q99 | C4 | yes | board confirmed | harness lane only user-confirmed |
+| front2 | intake L2 | 3, 7, 10 | CON24.7 | FAN_PWM2 | Q100 | B5 | yes | board confirmed | harness lane only user-confirmed |
+| front3 | intake L3 | 3, 7, 10 | CON26.7 | FAN_PWM4 | Q102 | A14 | yes | board confirmed | harness lane only user-confirmed |
+| rear0 | exhaust L0 | 3, 8, 10 | CON64.4 | FAN_GPIO44 | R704, 0 R direct | P15 | no | board confirmed | harness lane only user-confirmed |
+| rear1 | exhaust L1 | 3, 8, 10 | CON66.4 | FAN_GPIO46 | R706, 0 R direct | N15 | no | board confirmed | harness lane only user-confirmed |
+| rear2 | exhaust L2 | 3, 8, 10 | CON62.4 | FAN_GPIO42 | R702, 0 R direct | M14 | no | board confirmed | harness lane only user-confirmed |
+| rear3 | exhaust L3 | 3, 8, 10 | CON60.4 | FAN_GPIO40 | R700, 0 R direct | P5 | no | board confirmed | harness lane only user-confirmed |
+
+Front Pin 7 has optional +12V_FAN pull-ups R909/R894/R900/R918 and optional ground resistors R916/R895/R907/R925. Rear Pin 4 has only optional +3V3 pull-ups R977/R979/R975/R973; there is no rear Pin 4 +12 V pull-up. BRD-derived `assembly_status` is unknown and no BOM was found, so population and PWM high level are `PWM_HIGH_LEVEL_UNVERIFIED`.
+
+## Polarity truth table
+
+`logical_fan_on` is connector-requested PWM high time. The only RTL polarity conversion is `fan_board_output_adapter`.
+
+| Requested duty | logical_fan_on high fraction | Front FPGA ball | Front NPN sink | Front connector Pin 7 | Rear FPGA ball | Rear connector Pin 4 | Applied logical duty |
+| ---: | ---: | --- | --- | --- | --- | --- | ---: |
+| 0% | 0% | high | on | low | low | low | 0% |
+| 10% | 10% | low for 10% | off for 10% | high for 10% | high for 10% | high for 10% | 10% |
+| 50% | 50% | low for 50% | off for 50% | high for 50% | high for 50% | high for 50% | 50% |
+| 100% | 100% | low | off | high | high | high | 100% |
+
+On RTL reset/reconfiguration request and during output-bank initialization, the adapter requests 100%: front balls low and rear balls high. Both banks are sequentially initialized to PTC 0/FAN standby 10, then the design waits a complete PWM boundary before atomically releasing the boot full-speed request. BMC stale or global fault requests all eight fans at 100%; lane hard fault requests the affected front/rear pair at 100%. Ordinary STOPPED/standby uses 10%.
+
+## Evidence limits
+
+- `PTC_PWM_HZ=500` and `FAN_PWM_HZ=500` are independent generated parameters, currently using the equal-frequency shared carrier backend.
+- No exact fan manufacturer/model/datasheet was found. Fan 500 Hz compatibility is `EXPERIMENTAL_UNVERIFIED`.
+- `FAN_STANDBY_DUTY=10` is `EXPERIMENTAL_UNVERIFIED`; a conservative 30% should be considered before physical bring-up, but this task does not silently change it.
+- PWM waveform: simulation/formal only until the current verification receipts close.
+- Actual RPM: `NOT RUN`.
+- Actual airflow: `NOT RUN`.
+- Hardware, COM, JTAG, programming, and thermal performance: `NOT RUN`.

+ 63 - 71
docs/prod2u-6400-front-back-protocol.zh-CN.md

@@ -1,71 +1,63 @@
-# 6400 前后独立风道协议
-
-公共帧机制与 MRDIMM 相同:`A5 5A`、CRC-16/CCITT-FALSE、无 ACK、非法帧静默拒绝。上位机按所选目标使用对应 payload,不在 FPGA 内识别项目。
-
-## SET_ALL
-
-- type `0x01`,length `0x20`,总帧 38 字节
-- 前 24 字节 PTC,后 8 字节 FAN
-- 每字节 duty `0..100`;任一非法则整帧拒绝、不 commit、不喂狗
-- 成功无 ACK
-
-### PTC(丝印正向,传感器上、FPGA 下,左→右)
-
-| offset | 名称 | 网 | Ball | 连接器 |
-| ---: | --- | --- | --- | --- |
-| 0 | C1_PTC_L1 | HEAT6 | R7 | CON18.11(Pin13 同网) |
-| 1 | C1_PTC_L2 | HEAT5 | T6 | CON18.9 |
-| 2 | C1_PTC_L3 | HEAT4 | R5 | CON18.7 |
-| 3 | C1_PTC_L4 | HEAT3 | T4 | CON18.5 |
-| 4 | C1_PTC_L5 | HEAT2 | G16 | CON18.3 |
-| 5 | C1_PTC_L6 | HEAT1 | F16 | CON18.1 |
-| 6 | C2_PTC_L1 | HEAT12 | R3 | CON27.11(Pin13 同网) |
-| 7 | C2_PTC_L2 | HEAT11 | T2 | CON27.9 |
-| 8 | C2_PTC_L3 | HEAT10 | R1 | CON27.7 |
-| 9 | C2_PTC_L4 | HEAT9 | P1 | CON27.5 |
-| 10 | C2_PTC_L5 | HEAT8 | N1 | CON27.3 |
-| 11 | C2_PTC_L6 | HEAT7 | M1 | CON27.1 |
-| 12 | C3_PTC_L1 | HEAT18 | P7 | CON28.11(Pin13 同网) |
-| 13 | C3_PTC_L2 | HEAT17 | P8 | CON28.9 |
-| 14 | C3_PTC_L3 | HEAT16 | N16 | CON28.7 |
-| 15 | C3_PTC_L4 | HEAT15 | M16 | CON28.5 |
-| 16 | C3_PTC_L5 | HEAT14 | R16 | CON28.3 |
-| 17 | C3_PTC_L6 | HEAT13 | P16 | CON28.1 |
-| 18 | C4_PTC_L1 | HEAT24 | T12 | CON29.11(Pin13 同网) |
-| 19 | C4_PTC_L2 | HEAT23 | T13 | CON29.9 |
-| 20 | C4_PTC_L3 | HEAT22 | R10 | CON29.7 |
-| 21 | C4_PTC_L4 | HEAT21 | P10 | CON29.5 |
-| 22 | C4_PTC_L5 | HEAT20 | P9 | CON29.3 |
-| 23 | C4_PTC_L6 | HEAT19 | T9 | CON29.1 |
-
-Pin13 与该腔最后一路同网,不是第 25–28 路。
-
-### FAN(腔体优先,先进风后出风)
-
-| offset | 名称 | 映射 |
-| ---: | --- | --- |
-| 24 | C1_FAN_IN | FAN_PWM3 / B1 / CON25.7 |
-| 25 | C1_FAN_OUT | FAN_GPIO44 / P15 / CON64.4(PIN3 FG 不用) |
-| 26 | C2_FAN_IN | FAN_PWM1 / C4 / CON8.7 |
-| 27 | C2_FAN_OUT | FAN_GPIO46 / N15 / CON66.4(PIN3 FG 不用) |
-| 28 | C3_FAN_IN | FAN_PWM2 / B5 / CON24.7 |
-| 29 | C3_FAN_OUT | FAN_GPIO42 / M14 / CON62.4(PIN3 FG 不用) |
-| 30 | C4_FAN_IN | FAN_PWM4 / A14 / CON26.7 |
-| 31 | C4_FAN_OUT | FAN_GPIO40 / P5 / CON60.4(PIN3 FG 不用) |
-
-## PWM
-
-500 Hz,50,000 时钟/周期,每 phase 500 时钟,`logical_on = duty > phase`。PTC 高有效,FAN FPGA 脚反相。commit 原子切换 bank;物理脚在约 33 拍扫描窗内逐路更新。
-
-## Watchdog
-
-仅合法 commit 喂狗。30 s = 60,000 × 500 µs。超时 PTC 0 / FAN 10。下一帧合法 SET 清除。
-
-## 温度
-
-`GET_TEMPERATURE` 空 payload。一次扫描 27 项后只回一帧 `0x82`。顺序:0x49 / 0x48 / 0x4B,各寄存器 0x00..0x08。失败通道 `0xFF`,不改 PTC/FAN,不喂狗。
-
-## Golden
-
-- 全 0 SET:`A55A0120` + 32×`00` + `0D8C`
-- GET_TEMPERATURE:`A55A02006D7B`
+# 6400 前4进风/后4出风 Host 协议
+
+本页只描述当前 `6400-control`、`6400-identification` 与 `6400-sim-debug` 合同。机器可读权威为 `generated/6400/host-contract.json`。
+
+## 串口与帧
+
+- Host RS-232(CON78)和 Host TTL:921600 8N1;一次事务只使用其中一个口。
+- BMC UART:115200 8N1;本次不修改 BMC Poll/Response,也不给 BMC 增加 ACK。
+- 帧:`A5 5A | TYPE | LENGTH | PAYLOAD | CRC_LOW | CRC_HIGH`。
+- CRC-16/CCITT-FALSE 覆盖 TYPE、LENGTH、PAYLOAD,CRC 低字节先发。
+- Request 为 `0x01..0x3F`,DATA 为 `request_type | 0x40`,ACK 为 `request_type | 0x80`,`0xC0..0xFF` 保留。
+- Header、Length、CRC、TYPE、参数错误或 Profile 不支持的命令静默丢弃;没有 NACK、Sequence、Version、Project ID 或命令队列。
+
+## 命令与独立 ACK
+
+所有合法 Host 命令每次都返回一帧独立 ACK,重复合法命令也不能省略。
+
+| 请求 | Payload | 回复顺序 | Profile |
+| --- | --- | --- | --- |
+| `0x01 SET_TARGET` | 1 字节:`0` 或 `20..70` °C | 原子提交后 `0x81/LEN0` | 全部 |
+| `0x02 GET_SNAPSHOT` | 空 | 锁存 Bank/Epoch/固定字段后 `0x82/LEN0`,再 `0x42/LEN193` | 全部 |
+| `0x03 SET_STIMULUS` | 33 字节 | 原子提交后 `0x83/LEN0` | 仅 Identification/Sim-Debug |
+
+旧 `0x82/LEN193 SNAPSHOT_DATA` 定义已废止。Host 必须按 `WAIT_ACK → WAIT_DATA` 处理 GET,DATA 不能替代 ACK。GET 的 port selector 与 snapshot bank lock 一直保持到 `0x42` 最后一字节 CRC 的 UART Stop Bit 完成。
+
+## SET_STIMULUS Payload
+
+仅用于 `6400-identification` 和 `6400-sim-debug`;Production 完全移除其解码路径。
+
+| Offset | 字段 | 数量 | 范围 |
+| ---: | --- | ---: | --- |
+| 0 | duration_seconds | 1 | 1..255 秒 |
+| 1 | PTC duty | 24 | 每项 0..100% |
+| 25 | Front fan duty | 4 | 每项 0..100% |
+| 29 | Rear fan duty | 4 | 每项 0..100% |
+
+顺序严格为 24 PTC、Front0..3、Rear0..3。Stimulus 有限期自动退出且永远不能越过 BMC stale、74/76/77 °C 或 lane/global fault 安全优先级。
+
+## 风扇物理顺序
+
+| 逻辑输出 | Connector | Net / Ball | 板级极性 |
+| --- | --- | --- | --- |
+| Front0..3 | CON25.7 / CON8.7 / CON24.7 / CON26.7 | FAN_PWM3/B1, FAN_PWM1/C4, FAN_PWM2/B5, FAN_PWM4/A14 | Q101/Q99/Q100/Q102 反相 |
+| Rear0..3 | CON64.4 / CON66.4 / CON62.4 / CON60.4 | FAN_GPIO44/P15, FAN_GPIO46/N15, FAN_GPIO42/M14, FAN_GPIO40/P5 | 0 R 直连,不反相 |
+
+生产向量固定为 Front0..3 后 Rear0..3,`FAN_BOARD_INVERT_MASK=0x0F`。500 Hz、10% Standby、PWM High Level 仍是 `EXPERIMENTAL_UNVERIFIED`;实际 RPM、风量和硬件验证均 `NOT RUN`。
+
+## Golden Vector
+
+- SET_TARGET 0 °C:`A55A0101009DC8`
+- SET_TARGET 20 °C:`A55A010114289A`
+- SET_TARGET 70 °C:`A55A0101469FE0`
+- GET_SNAPSHOT:`A55A02006D7B`
+- SET_TARGET_ACK:`A55A8100A635`
+- GET_SNAPSHOT_ACK:`A55A8200F560`
+- SET_STIMULUS_ACK:`A55A8300C453`
+
+离线生成 HEX(不打开串口):
+
+```bash
+python3 tools/encode_6400_hex.py --profile 6400-control set-target 50
+python3 tools/encode_6400_hex.py --profile 6400-control get-snapshot
+```

+ 1 - 0
products/6400-identification/project.json

@@ -4,6 +4,7 @@
   "product": "6400-front-rear-v1",
   "top": "prod2u_6400_identification_top",
   "inherits": "products/6400-control/project.json",
+  "source_closure": "products/6400-identification/source-closure.json",
   "stimulus": true,
   "production": false
 }

+ 10 - 0
products/6400-identification/source-closure.json

@@ -0,0 +1,10 @@
+{
+  "schema": "prod2u-source-closure-v1",
+  "project_id": "6400-identification",
+  "top_module": "prod2u_6400_identification_top",
+  "inherits": "products/6400-control/source-closure.json",
+  "additional_sources": ["src/top/prod2u_6400_identification_top.v"],
+  "stimulus": true,
+  "production": false,
+  "forbidden_substrings": ["door_", "motor", "limit_gate", "host_watchdog", "EF2_PHY_PLL", "SET_ALL"]
+}

+ 1 - 0
products/6400-sim-debug/project.json

@@ -4,6 +4,7 @@
   "product": "6400-front-rear-v1",
   "top": "prod2u_6400_v1_top",
   "inherits": "products/6400-control/project.json",
+  "source_closure": "products/6400-sim-debug/source-closure.json",
   "stimulus": true,
   "simulation_only": true,
   "production": false

+ 11 - 0
products/6400-sim-debug/source-closure.json

@@ -0,0 +1,11 @@
+{
+  "schema": "prod2u-source-closure-v1",
+  "project_id": "6400-sim-debug",
+  "top_module": "prod2u_6400_v1_top",
+  "inherits": "products/6400-control/source-closure.json",
+  "parameter_overrides": {"ENABLE_STIMULUS": 1},
+  "stimulus": true,
+  "simulation_only": true,
+  "production": false,
+  "forbidden_substrings": ["door_", "motor", "limit_gate", "host_watchdog", "EF2_PHY_PLL", "SET_ALL"]
+}

+ 5 - 3
src/actuator/fan_board_output_adapter.v

@@ -1,10 +1,11 @@
 `timescale 1ns/1ps
-`include "generated/6400/prod2u_6400_v1_params.vh"
 
 // The only logical-to-board fan polarity adapter.
 // Vector order is {rear3..rear0, front3..front0}; bit 0..3 are the four
 // transistor-inverted front outputs, while bit 4..7 are direct rear outputs.
-module fan_board_output_adapter (
+module fan_board_output_adapter #(
+    parameter [7:0] BOARD_INVERT_MASK = 8'h0F
+) (
     input  wire [7:0] logical_fan_on,
     input  wire       boot_release,
     input  wire       force_full_speed,
@@ -13,13 +14,14 @@ module fan_board_output_adapter (
 );
     wire [7:0] requested_fan_on = (!boot_release || force_full_speed) ?
         8'hFF : logical_fan_on;
-    wire [7:0] fan_pwm_sink_enable = requested_fan_on ^ `FAN_BOARD_INVERT_MASK;
+    wire [7:0] fan_pwm_sink_enable = requested_fan_on ^ BOARD_INVERT_MASK;
 
     assign front_fan_ball = fan_pwm_sink_enable[3:0];
     assign rear_fan_ball = fan_pwm_sink_enable[7:4];
 
 `ifdef FORMAL
     always @* begin
+        assert(BOARD_INVERT_MASK == 8'h0F);
         if (!boot_release || force_full_speed) begin
             assert(front_fan_ball == 4'h0);
             assert(rear_fan_ball == 4'hF);

+ 3 - 0
src/actuator/pwm_bitmap_engine.v

@@ -16,6 +16,7 @@ module pwm_bitmap_engine #(
     input  wire [7:0]               duty_rd_data,
     output reg  [CHANNEL_COUNT-1:0] logical_bitmap,
     output reg                      phase_boundary,
+    output wire                     phase_boundary_advance,
     output reg                      deadline_miss,
     output wire [6:0]               phase_value,
     output wire                     scan_idle
@@ -53,6 +54,7 @@ module pwm_bitmap_engine #(
     assign duty_rd_addr = scan_addr;
     assign phase_value = {{(7-PHASE_BITS){1'b0}}, phase};
     assign scan_idle = !scanning && !capture_valid;
+    assign phase_boundary_advance = phase_clk == LAST_SLOT;
 
     always @(posedge clk or negedge rst_n) begin
         if (!rst_n) begin
@@ -126,6 +128,7 @@ module pwm_bitmap_engine #(
             assert(!deadline_miss);
             assert(phase <= LAST_PHASE);
             assert(phase_clk <= LAST_SLOT);
+            assert(phase_boundary_advance == (phase_clk == LAST_SLOT));
             if (phase_clk < CHANNEL_COUNT + 1)
                 assert(formal_scan_remaining == CHANNEL_COUNT + 1 - phase_clk);
             else

+ 7 - 5
src/top/prod2u_6400_v1_top.v

@@ -134,6 +134,7 @@ module prod2u_6400_v1_top #(
     wire [7:0] pwm_duty_data;
     wire [31:0] logical_bitmap;
     wire pwm_boundary;
+    wire pwm_boundary_advance;
     wire pwm_deadline_miss;
     wire [6:0] pwm_phase;
     wire pwm_scan_idle;
@@ -168,14 +169,14 @@ module prod2u_6400_v1_top #(
         if (!rst_n) begin
             boot_fan_release <= 1'b0;
             fan_force_full_speed <= 1'b1;
-        end else if (pwm_boundary) begin
+        end else if (pwm_boundary_advance) begin
             if (boot_init_complete)
                 boot_fan_release <= 1'b1;
             fan_force_full_speed <= bmc_stale || global_fault;
         end
     end
 
-    fan_board_output_adapter u_fan_board_adapter (
+    fan_board_output_adapter #(.BOARD_INVERT_MASK(`FAN_BOARD_INVERT_MASK)) u_fan_board_adapter (
         .logical_fan_on(logical_bitmap[31:24]),
         .boot_release(boot_fan_release),
         .force_full_speed(fan_force_full_speed),
@@ -313,7 +314,7 @@ module prod2u_6400_v1_top #(
         .host_target_seen(host_target_seen), .control_epoch(control_epoch),
         .safety_override_mask(safety_mask), .lane_fault_mask(lane_fault_mask),
         .global_fault(global_fault), .output_commit(output_commit), .stimulus_active(stimulus_active),
-        .pwm_phase_boundary(pwm_boundary), .pwm_scan_idle(pwm_scan_idle),
+        .pwm_phase_boundary(pwm_boundary_advance), .pwm_scan_idle(pwm_scan_idle),
         .boot_init_complete(boot_init_complete)
     );
     pwm_bitmap_engine #(
@@ -322,7 +323,8 @@ module prod2u_6400_v1_top #(
     ) u_pwm (
         .clk(sys_clk), .rst_n(rst_n), .duty_rd_addr(pwm_duty_addr),
         .duty_rd_data(pwm_duty_data), .logical_bitmap(logical_bitmap),
-        .phase_boundary(pwm_boundary), .deadline_miss(pwm_deadline_miss),
+        .phase_boundary(pwm_boundary), .phase_boundary_advance(pwm_boundary_advance),
+        .deadline_miss(pwm_deadline_miss),
         .phase_value(pwm_phase), .scan_idle(pwm_scan_idle)
     );
     thermal_snapshot_mux u_snapshot_mux (
@@ -346,7 +348,7 @@ module prod2u_6400_v1_top #(
         host_rs232_rx_sync, host_ttl_rx_sync, host_command_busy, frame_tx_done, bmc_tx_done,
         bmc_poll_count, bmc_snapshot_commit, ct_snapshot_commit, ct_i2c_busy, ct_control_raw,
         ct_control_valid, bmc_snapshot_valid, ct_snapshot_valid, output_commit,
-        stimulus_active, pwm_boundary, pwm_phase, pwm_scan_idle, host_crc_request_conflict,
+        stimulus_active, pwm_boundary, pwm_boundary_advance, pwm_phase, pwm_scan_idle, host_crc_request_conflict,
         boot_init_complete, boot_fan_release, fan_force_full_speed};
 
 `ifdef FORMAL

+ 13 - 0
src/transport/thermal_host_command.v

@@ -192,6 +192,19 @@ module thermal_host_command #(
                 assert(tx_payload_length == SNAPSHOT_LENGTH[7:0]);
                 assert(state == ST_SNAPSHOT_DATA_TX);
             end
+            if (formal_past_valid && $past(rst_n) &&
+                $past(state) == ST_SNAPSHOT_ACK_TX && $past(tx_done)) begin
+                assert(tx_start);
+                assert(tx_frame_type == 8'h42);
+                assert(tx_payload_length == SNAPSHOT_LENGTH[7:0]);
+                assert(!transaction_done);
+            end
+            if (formal_past_valid && $past(rst_n) &&
+                $past(state) == ST_SNAPSHOT_DATA_TX && $past(tx_done)) begin
+                assert(transaction_done);
+            end
+            if (state == ST_SNAPSHOT_ACK_TX || state == ST_SNAPSHOT_DATA_TX)
+                assert(busy && !transaction_done);
             if (formal_past_valid && $past(rst_n) &&
                 target_celsius != $past(target_celsius))
                 assert(target_commit);

+ 106 - 2
tests/cocotb/test_6400_v1_control_integration.py

@@ -3,15 +3,18 @@
 from __future__ import annotations
 
 import cocotb
-from cocotb.triggers import Timer, with_timeout
+from cocotb.triggers import ReadOnly, RisingEdge, Timer, with_timeout
 
 from thermal_6400_uart import (
     BMC_CLKS_PER_BIT,
     CLOCK_NS,
+    GET_SNAPSHOT,
+    GET_SNAPSHOT_ACK,
     HOST_CLKS_PER_BIT,
     SET_STIMULUS,
     SET_TARGET,
     SET_TARGET_ACK,
+    SNAPSHOT_DATA,
     bring_auto,
     check_pwm_timing,
     encode_frame,
@@ -34,7 +37,53 @@ def duties(snapshot: dict[str, object], name: str) -> list[int]:
 @cocotb.test()
 async def test_control_dual_host_sensor_safety_and_snapshot(dut):
     pwm_timing = cocotb.start_soon(check_pwm_timing(dut))
-    await bring_auto(dut)
+    await bring_auto(dut, verify_boot=True)
+
+    # GET is one locked two-frame transaction. Traffic on the alternate Host
+    # after ACK must not change port_sel, unlock snapshot banks, or commit a
+    # command before the 0x42 DATA frame's final physical stop bit retires.
+    get_state = {"ack": False, "done": False}
+
+    async def receive_locked_get() -> tuple[int, bytes]:
+        ack = await receive_frame(dut.host_ttl_tx)
+        assert ack == (GET_SNAPSHOT_ACK, b"")
+        get_state["ack"] = True
+        data = await receive_frame(dut.host_ttl_tx)
+        get_state["done"] = True
+        return data
+
+    target_before_locked_get = int(dut.current_target_mon.value)
+    get_task = cocotb.start_soon(receive_locked_get())
+    await send_uart(dut.host_ttl_rx, encode_frame(GET_SNAPSHOT), HOST_CLKS_PER_BIT)
+    while not get_state["ack"]:
+        await RisingEdge(dut.sys_clk)
+    assert int(dut.host_locked_mon.value) == 1
+    assert int(dut.host_port_sel_mon.value) == 1
+    assert int(dut.u_dut.snapshot_locked.value) == 1
+    alternate = cocotb.start_soon(
+        send_uart(dut.host_rs232_rx, encode_frame(SET_TARGET, b"\x46"), HOST_CLKS_PER_BIT)
+    )
+    while not get_state["done"]:
+        await RisingEdge(dut.sys_clk)
+        await ReadOnly()
+        assert int(dut.host_locked_mon.value) == 1
+        assert int(dut.host_port_sel_mon.value) == 1
+        assert int(dut.u_dut.snapshot_locked.value) == 1
+    data_kind, data_payload = await with_timeout(get_task, 5, "ms")
+    assert data_kind == SNAPSHOT_DATA and len(data_payload) == 193
+    # receive_frame completes at the center of the final stop bit; lock must
+    # still be present until uart_tx byte_done at the end of that stop bit.
+    assert int(dut.host_locked_mon.value) == 1
+    assert int(dut.u_dut.snapshot_locked.value) == 1
+    await alternate
+    await wait_for(
+        dut,
+        lambda: int(dut.host_locked_mon.value) == 0
+        and int(dut.u_dut.snapshot_locked.value) == 0,
+        cycles=100,
+        label="GET final-stop unlock",
+    )
+    assert int(dut.current_target_mon.value) == target_before_locked_get
 
     # Production must silently reject the identification-only command.
     rejected_payload = bytes([2, *([20] * 32)])
@@ -149,6 +198,39 @@ async def test_control_dual_host_sensor_safety_and_snapshot(dut):
     assert duties(hard, "front_applied")[0] == 100
     assert duties(hard, "rear_applied")[0] == 100
 
+    # Repeating a legal target while the lane hard fault is active must ACK
+    # but cannot reduce its applied airflow or its physical connector request.
+    old_control_epoch = int(dut.control_epoch_mon.value)
+    kind, payload = await host_transaction(dut, "rs232", SET_TARGET, b"\x41")
+    assert (kind, payload) == (SET_TARGET_ACK, b"")
+    await wait_for(
+        dut,
+        lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
+        cycles=1000,
+        label="hard-fault repeated target safe commit",
+    )
+    hard_after_target = await get_snapshot(dut, "ttl")
+    assert int(hard_after_target["lane_fault_mask"]) & 1
+    assert duties(hard_after_target, "front_applied")[0] == 100
+    assert duties(hard_after_target, "rear_applied")[0] == 100
+    for _ in range(2):
+        await wait_for(dut, lambda: int(dut.pwm_boundary_mon.value) == 1,
+                       cycles=600, label="hard-fault physical fan boundary")
+        await Timer(CLOCK_NS, units="ns")
+    assert not (int(dut.front_fan_pwm_out.value) & 0x1)
+    assert int(dut.rear_fan_pwm_out.value) & 0x1
+
+    # Requalify acquisition while retaining the hot lane, so the stale test
+    # below starts from an admitted runtime state rather than startup gating.
+    for _ in range(4):
+        await send_bmc_snapshot(dut, [77, *([60] * 23)])
+    await wait_for(
+        dut,
+        lambda: int(dut.control_state_mon.value) == 5,
+        cycles=1000,
+        label="hard-fault runtime requalification",
+    )
+
     # Three explicit age ticks without a new BMC epoch create global stale.
     await pulse_tick_1s(dut, 3)
     await wait_for(
@@ -163,6 +245,28 @@ async def test_control_dual_host_sensor_safety_and_snapshot(dut):
     assert duties(stale, "front_applied") == [100] * 4
     assert duties(stale, "rear_applied") == [100] * 4
 
+    # A legal target during global stale also ACKs without weakening the
+    # already-applied all-fan safety request.
+    old_control_epoch = int(dut.control_epoch_mon.value)
+    kind, payload = await host_transaction(dut, "ttl", SET_TARGET, b"\x41")
+    assert (kind, payload) == (SET_TARGET_ACK, b"")
+    await wait_for(
+        dut,
+        lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
+        cycles=1000,
+        label="stale target safe commit",
+    )
+    stale_after_target = await get_snapshot(dut, "rs232")
+    assert stale_after_target["global_fault"] == 1
+    assert duties(stale_after_target, "front_applied") == [100] * 4
+    assert duties(stale_after_target, "rear_applied") == [100] * 4
+    for _ in range(2):
+        await wait_for(dut, lambda: int(dut.pwm_boundary_mon.value) == 1,
+                       cycles=600, label="stale physical fan boundary")
+        await Timer(CLOCK_NS, units="ns")
+    assert int(dut.front_fan_pwm_out.value) == 0x0
+    assert int(dut.rear_fan_pwm_out.value) == 0xF
+
     # Three complete safe epochs retain the clamp through the release commit;
     # the following epoch resumes only the normal slew-limited ramp.
     for _ in range(3):

+ 75 - 6
tests/cocotb/thermal_6400_uart.py

@@ -148,12 +148,80 @@ async def pulse_tick_1s(dut, count: int = 1) -> None:
         dut.tick_1s_test.value = 0
 
 
-async def initialize(dut) -> None:
+def fan_connector_value(dut) -> int:
+    front_ball = int(dut.front_fan_pwm_out.value)
+    rear_ball = int(dut.rear_fan_pwm_out.value)
+    return (rear_ball << 4) | ((~front_ball) & 0x0F)
+
+
+async def verify_boot_full_speed_then_standby(dut) -> None:
+    # POR, both-RAM initialization, and the full-boundary handoff must expose
+    # only the full-speed connector request. Capture the pre-edge advance
+    # signal to prove the release itself occurs on the atomic PWM edge.
+    saw_reset = False
+    previous_release = 0
+    for _ in range(4000):
+        await FallingEdge(dut.sys_clk)
+        pre_boundary = int(dut.u_dut.pwm_boundary_advance.value)
+        await RisingEdge(dut.sys_clk)
+        await ReadOnly()
+        reset_n = int(dut.rst_n_mon.value)
+        release = int(dut.u_dut.boot_fan_release.value)
+        if not reset_n:
+            saw_reset = True
+        if not release:
+            assert fan_connector_value(dut) == 0xFF
+            assert int(dut.front_fan_pwm_out.value) == 0x0
+            assert int(dut.rear_fan_pwm_out.value) == 0xF
+        if release and not previous_release:
+            assert pre_boundary == 1
+            break
+        previous_release = release
+    else:
+        raise AssertionError("boot fan release did not complete")
+    assert saw_reset
+    assert int(dut.u_dut.boot_init_complete.value) == 1
+
+    # Reset-age BMC stale has higher safety priority than standby, so physical
+    # output correctly remains 100% after the boot flag itself releases.
+    assert fan_connector_value(dut) == 0xFF
+    await FallingEdge(dut.sys_clk)
+    await send_bmc_snapshot(dut, [60] * 24)
+    await wait_for(
+        dut,
+        lambda: int(dut.u_dut.bmc_stale.value) == 0,
+        cycles=200,
+        label="fresh BMC before standby waveform",
+    )
+
+    # Once BMC is fresh, the initialized bank is FAN_STANDBY_DUTY=10 for all
+    # eight outputs. Start at a later phase-zero boundary so the boundary-
+    # latched stale override has already retired without a narrow pulse.
+    while True:
+        await RisingEdge(dut.sys_clk)
+        await ReadOnly()
+        if int(dut.pwm_boundary_mon.value) and int(dut.pwm_phase_mon.value) == 0:
+            break
+    high_counts = [0] * 8
+    for sample in range(50000):
+        connector = fan_connector_value(dut)
+        for index in range(8):
+            high_counts[index] += (connector >> index) & 1
+        if sample != 49999:
+            await RisingEdge(dut.sys_clk)
+            await ReadOnly()
+    assert high_counts == [5000] * 8
+
+
+async def initialize(dut, *, verify_boot: bool = False) -> None:
     dut.host_rs232_rx.value = 1
     dut.host_ttl_rx.value = 1
     dut.bmc_rs232_rx.value = 1
     dut.tick_1s_test.value = 0
-    await with_timeout(RisingEdge(dut.rst_n_mon), 1, "ms")
+    if verify_boot:
+        await verify_boot_full_speed_then_standby(dut)
+    else:
+        await with_timeout(RisingEdge(dut.rst_n_mon), 1, "ms")
     await wait_for(
         dut,
         lambda: int(dut.ct_epoch_mon.value) >= 1,
@@ -163,15 +231,16 @@ async def initialize(dut) -> None:
     assert int(dut.ct_valid_mask_mon.value) == (1 << 27) - 1
     await wait_for(
         dut,
-        lambda: int(dut.control_state_mon.value) == 2,
+        lambda: int(dut.control_state_mon.value) in (2, 3),
         cycles=1000,
-        label="PREHEAT_CT",
+        label="PREHEAT_CT or already-qualified WAIT_BMC_STABLE",
     )
     assert int(dut.global_fault_mon.value) == 0
+    await FallingEdge(dut.sys_clk)
 
 
-async def bring_auto(dut, temperature: int = 60) -> None:
-    await initialize(dut)
+async def bring_auto(dut, temperature: int = 60, *, verify_boot: bool = False) -> None:
+    await initialize(dut, verify_boot=verify_boot)
     for _ in range(4):
         await send_bmc_snapshot(dut, [temperature] * 24)
     await wait_for(

+ 2 - 1
tests/formal/6400_pwm_properties.sby

@@ -11,10 +11,11 @@ boolector: smtbmc boolector
 z3: smtbmc z3 -- --noincr
 
 [script]
-read_verilog -formal -D FORMAL pwm_bitmap_engine.v
+read_verilog -formal -D FORMAL pwm_bitmap_engine.v fan_board_output_adapter.v
 read_verilog -formal 6400_pwm_properties_formal.v
 prep -top thermal_6400_pwm_properties_formal
 
 [files]
 ../../src/actuator/pwm_bitmap_engine.v
+../../src/actuator/fan_board_output_adapter.v
 6400_pwm_properties_formal.v

+ 15 - 1
tests/formal/6400_pwm_properties_formal.v

@@ -3,12 +3,22 @@ module thermal_6400_pwm_properties_formal (
     input wire rst_n
 );
     (* anyseq *) reg [7:0] duty_data;
+    (* anyseq *) reg boot_release;
+    (* anyseq *) reg force_full_speed;
+    wire [31:0] logical_bitmap;
+    wire [3:0] front_fan_ball;
+    wire [3:0] rear_fan_ball;
 
     pwm_bitmap_engine dut (
         .clk(clk), .rst_n(rst_n), .duty_rd_addr(), .duty_rd_data(duty_data),
-        .logical_bitmap(), .phase_boundary(), .deadline_miss(),
+        .logical_bitmap(logical_bitmap), .phase_boundary(), .phase_boundary_advance(), .deadline_miss(),
         .phase_value(), .scan_idle()
     );
+    fan_board_output_adapter u_board (
+        .logical_fan_on(logical_bitmap[31:24]),
+        .boot_release(boot_release), .force_full_speed(force_full_speed),
+        .front_fan_ball(front_fan_ball), .rear_fan_ball(rear_fan_ball)
+    );
 
     reg [1:0] reset_cycles = 0;
     always @(posedge clk) begin
@@ -17,5 +27,9 @@ module thermal_6400_pwm_properties_formal (
             reset_cycles <= reset_cycles + 1'b1;
         end else assume(rst_n);
         assume(duty_data <= 100);
+        assert(front_fan_ball == ~((!boot_release || force_full_speed) ?
+            4'hF : logical_bitmap[27:24]));
+        assert(rear_fan_ball == ((!boot_release || force_full_speed) ?
+            4'hF : logical_bitmap[31:28]));
     end
 endmodule

+ 4 - 2
tests/sim/pwm_bitmap_engine_tb.v

@@ -8,6 +8,7 @@ module pwm_bitmap_engine_tb;
     reg [7:0] duty_data;
     wire [31:0] bitmap;
     wire boundary;
+    wire boundary_advance;
     wire miss;
     wire [6:0] phase;
     wire idle;
@@ -34,7 +35,8 @@ module pwm_bitmap_engine_tb;
 
     pwm_bitmap_engine dut (
         .clk(clk), .rst_n(rst_n), .duty_rd_addr(addr), .duty_rd_data(duty_data),
-        .logical_bitmap(bitmap), .phase_boundary(boundary), .deadline_miss(miss),
+        .logical_bitmap(bitmap), .phase_boundary(boundary),
+        .phase_boundary_advance(boundary_advance), .deadline_miss(miss),
         .phase_value(phase), .scan_idle(idle)
     );
     fan_board_output_adapter board_adapter (
@@ -190,7 +192,7 @@ module pwm_bitmap_engine_tb;
                 ptc_pins, fan_balls, fan_connector_pwm);
         if (miss) $fatal(1, "scan deadline miss after safety transition");
 
-        $display("PASS: L6 PWM 32ch 500Hz duties=0,1,2,50,99,100 atomic safety polarity");
+        $display("PASS: L6 PWM 32ch 500Hz duties include 10/50/100 atomic 0x0F board polarity");
         $finish;
     end
 endmodule

+ 7 - 0
tests/unit/test_6400_v1_contract.py

@@ -15,6 +15,13 @@ def test_channel_map_is_exact_and_holdout_is_not_disabled() -> None:
     assert sum(bool(row["primary_cohort"]) for row in mapping["channels"]) == 18
     assert sum(not bool(row["primary_cohort"]) for row in mapping["channels"]) == 6
     assert all(bool(row["enabled"]) for row in mapping["channels"])
+    fans = mapping["fan_outputs"]
+    assert [row["connector"] for row in fans] == [
+        "CON25", "CON8", "CON24", "CON26", "CON64", "CON66", "CON62", "CON60"
+    ]
+    assert not {"CON31", "CON32", "CON33", "CON34", "CON35", "CON68"} & {
+        row["connector"] for row in fans
+    }
 
 
 def test_snapshot_layout_is_fixed_193_bytes() -> None:

+ 37 - 0
tests/unit/test_encode_6400_hex.py

@@ -0,0 +1,37 @@
+from pathlib import Path
+
+import pytest
+
+from tools.encode_6400_hex import Encoder
+
+
+ROOT = Path(__file__).resolve().parents[2]
+
+
+def test_target_and_get_match_generated_golden_vectors() -> None:
+    encoder = Encoder()
+    golden = encoder.contract["golden_vectors"]["frames"]
+    assert encoder.set_target("6400-control", 0).hex().upper() == golden["set_target_stop"]
+    assert encoder.set_target("6400-control", 20).hex().upper() == golden["set_target_20"]
+    assert encoder.set_target("6400-control", 70).hex().upper() == golden["set_target_70"]
+    assert encoder.get_snapshot("6400-control").hex().upper() == golden["get_snapshot"]
+
+
+def test_profile_isolation_and_stimulus_layout() -> None:
+    encoder = Encoder()
+    with pytest.raises(ValueError, match="not supported"):
+        encoder.set_stimulus("6400-control", 1, [0] * 24, [0] * 4, [0] * 4)
+    result = encoder.set_stimulus(
+        "6400-identification", 3, list(range(24)), [10, 20, 30, 40], [50, 60, 70, 80]
+    )
+    assert result[2:4] == bytes((0x03, 33))
+    assert result[4] == 3
+    assert list(result[5:29]) == list(range(24))
+    assert list(result[29:33]) == [10, 20, 30, 40]
+    assert list(result[33:37]) == [50, 60, 70, 80]
+
+
+def test_only_canonical_profile_names_are_accepted() -> None:
+    encoder = Encoder()
+    with pytest.raises(ValueError, match="unknown canonical profile"):
+        encoder.get_snapshot("production")

+ 127 - 0
tools/encode_6400_hex.py

@@ -0,0 +1,127 @@
+#!/usr/bin/env python3
+"""Offline 6400 Host HEX encoder; never opens a serial or hardware device."""
+
+from __future__ import annotations
+
+import argparse
+import json
+from pathlib import Path
+import sys
+from typing import Iterable
+
+
+ROOT = Path(__file__).resolve().parents[1]
+DEFAULT_CONTRACT = ROOT / "generated" / "6400" / "host-contract.json"
+
+
+def crc16_ccitt_false(data: bytes) -> int:
+    value = 0xFFFF
+    for octet in data:
+        value ^= octet << 8
+        for _ in range(8):
+            value = ((value << 1) ^ 0x1021) & 0xFFFF if value & 0x8000 else (value << 1) & 0xFFFF
+    return value
+
+
+def frame(frame_type: int, payload: bytes = b"") -> bytes:
+    if len(payload) > 255:
+        raise ValueError("payload exceeds one-byte wire length")
+    body = bytes((frame_type, len(payload))) + payload
+    checksum = crc16_ccitt_false(body)
+    return b"\xA5\x5A" + body + checksum.to_bytes(2, "little")
+
+
+class Encoder:
+    def __init__(self, contract_path: Path = DEFAULT_CONTRACT) -> None:
+        self.contract_path = contract_path
+        self.contract = json.loads(contract_path.read_text(encoding="utf-8"))
+        self.profiles = self.contract["canonical_profiles"]
+        self.commands = self.contract["wire"]["commands"]
+
+    def _type(self, profile: str, command: str) -> int:
+        if profile not in self.profiles:
+            raise ValueError(f"unknown canonical profile: {profile}")
+        if command not in self.profiles[profile]["allowed_commands"]:
+            raise ValueError(f"{command} is not supported by {profile}")
+        return int(self.commands[command]["type"])
+
+    def set_target(self, profile: str, target_celsius: int) -> bytes:
+        if target_celsius != 0 and not 20 <= target_celsius <= 70:
+            raise ValueError("target must be 0 or 20..70 C")
+        return frame(self._type(profile, "SET_TARGET"), bytes((target_celsius,)))
+
+    def get_snapshot(self, profile: str) -> bytes:
+        return frame(self._type(profile, "GET_SNAPSHOT"))
+
+    def set_stimulus(
+        self,
+        profile: str,
+        duration_seconds: int,
+        ptc: Iterable[int],
+        front: Iterable[int],
+        rear: Iterable[int],
+    ) -> bytes:
+        values = [duration_seconds, *ptc, *front, *rear]
+        expected = self.commands["SET_STIMULUS"]["payload_fields"]
+        counts = [int(field["count"]) for field in expected]
+        if len(values) != sum(counts):
+            raise ValueError("SET_STIMULUS requires duration + 24 PTC + 4 Front + 4 Rear values")
+        offset = 0
+        for field in expected:
+            count = int(field["count"])
+            minimum = int(field["minimum"])
+            maximum = int(field["maximum"])
+            for value in values[offset : offset + count]:
+                if not minimum <= value <= maximum:
+                    raise ValueError(f"{field['name']} must be {minimum}..{maximum}")
+            offset += count
+        return frame(self._type(profile, "SET_STIMULUS"), bytes(values))
+
+
+def percent_list(text: str, count: int, label: str) -> list[int]:
+    values = [int(value.strip()) for value in text.split(",") if value.strip()]
+    if len(values) != count:
+        raise argparse.ArgumentTypeError(f"{label} requires exactly {count} comma-separated percentages")
+    if any(value < 0 or value > 100 for value in values):
+        raise argparse.ArgumentTypeError(f"{label} percentages must be 0..100")
+    return values
+
+
+def main(argv: list[str] | None = None) -> int:
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument("--contract", type=Path, default=DEFAULT_CONTRACT)
+    parser.add_argument("--profile", required=True)
+    subparsers = parser.add_subparsers(dest="command", required=True)
+    target_parser = subparsers.add_parser("set-target")
+    target_parser.add_argument("celsius", type=int)
+    subparsers.add_parser("get-snapshot")
+    stimulus_parser = subparsers.add_parser("set-stimulus")
+    stimulus_parser.add_argument("--duration", type=int, required=True)
+    stimulus_parser.add_argument("--ptc", required=True)
+    stimulus_parser.add_argument("--front", required=True)
+    stimulus_parser.add_argument("--rear", required=True)
+    args = parser.parse_args(argv)
+
+    encoder = Encoder(args.contract)
+    if args.command == "set-target":
+        result = encoder.set_target(args.profile, args.celsius)
+    elif args.command == "get-snapshot":
+        result = encoder.get_snapshot(args.profile)
+    else:
+        result = encoder.set_stimulus(
+            args.profile,
+            args.duration,
+            percent_list(args.ptc, 24, "PTC"),
+            percent_list(args.front, 4, "Front"),
+            percent_list(args.rear, 4, "Rear"),
+        )
+    print(result.hex().upper())
+    return 0
+
+
+if __name__ == "__main__":
+    try:
+        raise SystemExit(main())
+    except (KeyError, ValueError, json.JSONDecodeError) as exc:
+        print(f"ERROR: {exc}", file=sys.stderr)
+        raise SystemExit(2)

+ 3 - 0
tools/generate_6400_v1.py

@@ -145,6 +145,9 @@ def validate_fans(mapping: dict[str, Any], fan: dict[str, Any]) -> None:
         (31, 3, "CON60", 4, "FAN_GPIO40", "R700_0R_DIRECT", "P5", False),
     )
     rows = mapping.get("fan_outputs", [])
+    forbidden_connectors = {"CON31", "CON32", "CON33", "CON34", "CON35", "CON68"}
+    if forbidden_connectors & {str(row.get("connector")) for row in rows}:
+        raise ValueError("obsolete 8000/CON31-35/68 fan mapping is forbidden in 6400")
     for name, expected in (("front", expected_front), ("rear", expected_rear)):
         actual = tuple(
             (int(row["output_index"]), int(row["lane"]), row["connector"], int(row["pin"]),

+ 1 - 0
tools/run_6400_v1.py

@@ -90,6 +90,7 @@ def unit() -> None:
         "pytest", "-q",
         "tests/unit/test_6400_v1_contract.py",
         "tests/unit/test_6400_v1_source_closure.py",
+        "tests/unit/test_encode_6400_hex.py",
     ])