Update FPGA and Vivado skills

This commit is contained in:
Myfro9
2026-07-14 18:18:17 +08:00
parent d20ec12fee
commit bceafcd58c
14 changed files with 1707 additions and 14 deletions
+84 -13
View File
@@ -4,7 +4,7 @@ description: >
Run the fpga-imx6-flow LangGraph workflow at E:\LangGraph_Design\FPGA-imx6-flow —
the closed-loop SMOD (FPGA + i.MX6) hardware-in-the-loop design/debug pipeline:
power on the board, connect JTAG, program bitstream/flash, restart the imx6 app,
analyze (ILA + COM6 serial), judge against design requirements, and iterate by
analyze (ILA + imx6 serial console), judge against design requirements, and iterate by
modifying RTL/imx6 code. It drives the graph in-process (no langgraph dev) and
hands the 5 interrupts (analyze / meets-requirement / propose / modify-FPGA /
modify-imx6) back to this Claude session to execute.
@@ -43,8 +43,8 @@ USB-Blast 处于连接状态时给板卡上电或断电(保护 JTAG 适配器
标准时序(图拓扑已按此实现,手动操作或写 `tools_*` / 真机脚本时也必须遵守):
```
断电(COM8 power_off) → 确认已断电 → 断开USB-Blast(COM4 blast_off) → 确认已断开
→ 上电(COM8 power_on) → 确认已上电 → 连接USB-Blast(COM4 blast_on) → 连接JTAG/烧写/抓ILA
断电(power_off) → 确认已断电 → 断开USB-Blast(blast_off) → 确认已断开
→ 上电(power_on) → 确认已上电 → 连接USB-Blast(blast_on) → 连接JTAG/烧写/抓ILA
```
**烧写 flash 的完整闭环**(固化后必须断电重启从 flash 加载再验证):
@@ -59,7 +59,12 @@ USB-Blast 处于连接状态时给板卡上电或断电(保护 JTAG 适配器
`power_off` 做整机断电重启,再次走完上述上电时序后才 `analyze`(抓ILA验证)。
- **强化确认**:`power_on` 节点在上电前调用 `_ensure_blast_off_before_power()` 兜底确认
USB-Blast 已断开;若发现仍连接会强制断开并在 `history` 标记 `rule_violation=True`。
- vivado-mcp 工具:`power_on`/`power_off`(COM8 继电器)、`USB_Blast_on`/`USB_Blast_off`(COM4)。
- 两个继电器的**串口号不在本工作流里绑定**:唯一来源是 `~/vivado_mcp_usb.conf`(逐机而异,
不入库)。`app/tools_hw.py` 通过 `vivado_mcp.serial_config.load_serial_ports()` 读取它,
串口收发/组帧/CRC 也复用 `vivado_mcp.serial_io`——协议只有一份实现。
文件不存在时调 vivado-mcp 的 **`detect_serial_relays`** 工具自动探测生成。
(对应的 MCP 工具是 `power_on`/`power_off`/`USB_Blast_on`/`USB_Blast_off`,和这里的
`tools_hw` 走同一套底层。)
> **Run via the env python directly** (not bare `conda run`): on this Windows GBK
> console, `conda run` re-prints the child's UTF-8 stdout through a GBK codec and
@@ -90,9 +95,17 @@ if (-not (Test-Path $py)) { Write-Host "[MISSING] langgraph env" } else {
`langgraph` + `langgraph-checkpoint-sqlite` and the Vivado link). Do not proceed
until it succeeds.
**For a real-hardware run** (`--real`), additionally confirm: `env_config.json`'s
`VIVADO_BIN_PATH` is valid; the vivado-mcp `power_on`/`USB_Blast_on` tools are
available; COM4/COM6/COM8 are present (`[System.IO.Ports.SerialPort]::GetPortNames()`).
**For a real-hardware run** (`--real`), additionally confirm the machine's two config
files — **both live in `~`, neither is in the repo** (they hold COM numbers, VM/imx6
passwords, and the Vivado path, all of which differ per machine):
| 文件 | 装什么 | 缺了怎么办 |
|---|---|---|
| `~/vivado_mcp_usb.conf` | 电源继电器 + USB-Blast 继电器的 COM 号 | 调 vivado-mcp 的 **`detect_serial_relays`** 工具自动探测生成 |
| `~/fpga_imx6_flow.json` | imx6 控制台 COM 号 (`ports.imx6`)、`VIVADO_BIN_PATH`、虚拟机/imx6 口令 | 照工程根的 `fpga_imx6_flow.example.json` 手工创建 |
List the machine's ports with `[System.IO.Ports.SerialPort]::GetPortNames()`.
工程根目录下**不该**再有 `env_config.json`——它已废弃,`app/config.py` 见到就报错。
**Default runs are MOCK** (dry-run of the design loop with no hardware), because the
workflow's `tools_*` real-hardware paths are still TODO — see "Mock vs real" below.
@@ -122,7 +135,7 @@ it, then resume the **same `--thread-id`** with a JSON payload. Repeat until exi
| `action` | excalidraw node | What you (the session) do | Resume JSON |
|---|---|---|---|
| `analyze` | 通过ila/串口分析 | Grab COM6 serial log + pull ILA waveform (vivado-mcp); summarize | `{"analysis_log":"<摘要/路径>"}` |
| `analyze` | 通过ila/串口分析 | Grab imx6 serial log + pull ILA waveform (vivado-mcp); summarize | `{"analysis_log":"<摘要/路径>"}` |
| `meets_requirement` | 符合设计要求? | Judge the analysis against the design requirement | `{"meets": true}` or `{"meets": false}` |
| `propose` | 分析原因,提出修改方案 | Diagnose root cause; decide what to change + next program mode | `{"reason":"...","need_fpga": true/false,"need_imx6": true/false,"program_mode":"bitstream"或"flash"}` |
| `modify_fpga` | 改 RTL→综合→出 bit/flash | Edit RTL, run Vivado synth/impl, produce bit + flash files | `{"bit_path":"...","flash_path":"...","program_mode":"flash"}` |
@@ -160,17 +173,75 @@ To abandon a paused run and start clean, delete `<project>\runs\skill_checkpoint
- **MOCK (default)** — `FPGA_IMX6_MOCK=1`; hardware/check nodes return success
immediately. Use this to dry-run the *design-loop logic* and the 5 interrupts with
no board attached. Great for demonstrating/validating the flow.
- **Real (`--real`)** — drives actual hardware. Requires the project's
`app/tools_hw.py` / `tools_vivado.py` / `tools_imx6.py` real paths to be implemented
(they currently raise `NotImplementedError` as TODO — they will reuse the proven
vivado-mcp serial/Vivado logic). Until then, `--real` fails at the first hardware
node; tell the user to wire the tools first (see `Notes/Task00.md` §7).
- **Real (`--real`)** — drives actual hardware. The `tools_hw` (power + USB-Blast relays,
ports from `~/vivado_mcp_usb.conf`), `tools_imx6` (console restart/kill/log, port from
`~/fpga_imx6_flow.json`'s `ports.imx6`), and `tools_vivado` (JTAG program/flash) real paths are
**now implemented and validated end-to-end (2026-07-05)** on the SMOD_ATSC board. Getting there
took **7 fixes** — see memory `fpga-imx6-flow-tx-safe`: power_on waits `sys init over` before
JTAG (else TX dies); `_PROJ`→SMOD_ATSC; `deploy_app`→no-op (deploy out-of-band, see above);
driver multi-interrupt resume (map by `action`); `power_off` blast-off-first + check retry guard
(else infinite loop); serial open-retry on transient err5 (now in `vivado_mcp.serial_io`);
`program_flash`→proven
`/fpga_flash` flasher + Mfg-ID verify (old tcl was a false-positive). Verify a flash landed with
JTAG `get_hw_ilas` (iter0 = **1 ILA / 0 VIO**; golden = **0 ILA / 2 VIO**).
## imx6 access + file transfer (modify_imx6 / deploy step) — PROVEN 2026-07-05
The `deploy_app` graph node is a no-op (deploy is done **out-of-band by the session**).
Here is the working recipe for the `modify_imx6` interrupt (cross-compile HEAD's app and
push it to the imx6). All of this is **network-based and fast** — no slow serial file push.
**Hosts / creds**
- **imx6 mgmt: `192.168.1.143`** (Windows host is on `192.168.1.125`, same subnet — `ping` works).
The old memory "imx6 not reachable over the network" is **outdated**; the mgmt port is reachable.
Login: **`root` / `anywavecom`**. (The serial console still works too but its login auto-logs-out and
is flaky; prefer network SSH for imx6 shell/log reads.)
- **Cross-compile VM: `bowei@192.168.223.128`** (Ubuntu, password **`lr7402`** — ask the user, don't
guess/brute-force). Toolchain env-setup:
`/opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi`.
If VM SSH gives `kex_exchange_identification: Connection closed`, the VM's sshd is down/hung —
ask the user to `sudo systemctl restart sshd`.
**SSH library quirk (critical)**
- The imx6's SSH server is **old (legacy ciphers + `ssh-rsa` host key)**. paramiko **5.0 fails**
(`unknown cipher` / `no acceptable host key`). Install **paramiko 2.12** to a temp dir and use it
for the imx6 (it has TripleDES/aes-cbc/ssh-rsa):
`python -m pip install --target <dir> paramiko==2.12.0` then `PYTHONPATH=<dir> python ... -W ignore`.
The **VM** SSH is modern, so the env's paramiko 5.0 works for the VM (or use 2.12 for both).
- The imx6 SSH has **no SFTP subsystem** (`open_sftp()` → `EOF during negotiation`). Transfer files
via **`cat > file` over an exec channel**:
```python
ch = imx6_client.get_transport().open_session()
ch.exec_command("cat > /aw/anywave/app/imx_atsc_app_head")
with open(local_bin, "rb") as f: ch.sendall(f.read())
ch.shutdown_write(); ch.recv_exit_status() # 0 = ok
```
(The VM has SFTP; `open_sftp().get(...)` works there.)
**Full modify_imx6 flow (validated)**
1. Windows: `git archive --format=tar -o head_atsc.tar HEAD:imx6/src/atsc_app` (13 MB, self-contained).
2. paramiko→VM (pw `lr7402`): SFTP the tar up; extract to a **FRESH dir** (`~/atsc_head_build`, never
touch `atsc_tsoip_build/` etc.); build:
`bash -lc 'source <envsetup>; cd ~/atsc_head_build && make'` → output `imx_atsc_app` (~2.92 MB ELF).
3. paramiko→VM SFTP the built `imx_atsc_app` down to Windows.
4. paramiko-2.12→imx6 (pw `anywavecom`): `cat >`-push it to `/aw/anywave/app/imx_atsc_app_head`,
`chmod 755`, `cp -a imx_atsc_app_head imx_atsc_app` (swap active; golden stays as
`imx_atsc_app.bak_pre_rx1`), md5-verify.
5. Cold-boot (tools_hw blast_off→power_off→power_on, TX-safe) so rc.local runs the new app.
6. Verify: network SSH grep `/var/module_log/imx_atsc_app.log` for `TALISE_radioOn` / `fb init state ok`
/ `fpga[0xBB]=0x03` (sync=1/tvalid=1); spectrum for TX; (ILA needs an `.ltx` → skip unless re-impl).
> The `git HEAD` app (b07d73b) is the known-good **RX1-on-framerA (M=4/lane0x03/RX1RX2) + correct TX**
> build. On-device `imx_atsc_app.rx1` and any `M=2/lane0x04` variant **break TX** — do not use them.
## Troubleshooting
| Symptom | Fix |
|---|---|
| `UnicodeEncodeError: 'gbk' ...` | Don't use bare `conda run`; use the env `python.exe` or `conda run --no-capture-output`. |
| imx6 SSH `unknown cipher` / `no acceptable host key` (paramiko 5) | Use **paramiko 2.12** (temp `--target` dir) for the imx6 legacy SSH; see "imx6 access" above. |
| imx6 `open_sftp` → `EOF during negotiation` | imx6 has no SFTP subsystem; push files via `cat > file` over an exec channel. |
| VM SSH `kex_exchange_identification: Connection closed` | VM sshd down/hung — user `sudo systemctl restart sshd`. |
| `import failed ... Run /langgraph-vivado-install` | The `langgraph` env is missing/incomplete → run `/langgraph-vivado-install`. |
| Exit 1 `NotImplementedError ... tools_*` | A `--real` run hit an unwired hardware tool. Run without `--real` (mock), or implement `tools_*`. |
| `resume` seems to start over | You passed a different `--thread-id` than `start`. Use the same one. |
+22 -1
View File
@@ -95,13 +95,32 @@ def main() -> None:
graph.invoke(init, cfg)
elif args.command == "resume":
payload = json.loads(args.resume_json) if args.resume_json else {}
graph.invoke(Command(resume=payload), cfg)
snap0 = graph.get_state(cfg)
pend = [intr for task in snap0.tasks for intr in task.interrupts]
if len(pend) <= 1:
graph.invoke(Command(resume=payload), cfg)
else:
# Multiple interrupts pending (parallel fan-out, e.g. modify_fpga +
# modify_imx6). payload must be a map keyed by each interrupt's "action"
# (or interrupt id); resume them all at once with an id->value map.
resume_map = {}
for intr in pend:
val = intr.value if isinstance(intr.value, dict) else {}
action = val.get("action")
if action in payload:
resume_map[intr.id] = payload[action]
elif intr.id in payload:
resume_map[intr.id] = payload[intr.id]
else:
resume_map[intr.id] = {}
graph.invoke(Command(resume=resume_map), cfg)
# status: no invoke, just snapshot
snap = graph.get_state(cfg)
except Exception as exc: # noqa: BLE001
_emit({"status": "error", "error": str(exc)}, 1)
if snap.next:
all_intr = [intr.value for task in snap.tasks for intr in task.interrupts]
_emit({
"status": "interrupt",
"thread_id": args.thread_id,
@@ -109,6 +128,8 @@ def main() -> None:
"next": list(snap.next),
"iteration": snap.values.get("iteration"),
"interrupt": _pending_interrupt(snap),
"pending_interrupts": all_intr,
"pending_count": len(all_intr),
}, 2)
else:
_emit({