Przeglądaj źródła

docs/tools: record 6400 V2.0 live hardware burn, power config and 921600 serial verification

Prod2U Recovery 1 miesiąc temu
rodzic
commit
df3d2d5eaa
2 zmienionych plików z 165 dodań i 1 usunięć
  1. 21 1
      RECOVERY_STATE.md
  2. 144 0
      tools/remote_flash_cpld.py

+ 21 - 1
RECOVERY_STATE.md

@@ -427,4 +427,24 @@ Updated: 2026-09-21 (recovery round). Keep this file short; details live in the
   4. `hth-platform` pytest 124 项用例 100% PASS;
   5. 压测工具 `prod2u_load_sweep.py` io-stress 自动化测试 PASS;
   6. Windows 交付包完整到位并通过远程 PowerShell SHA-256 校验。
-
+### 18. 6400 V2.0 实板硬件烧录、休眠彻底禁用与串口 921600 原生命令闭环实测
+- **改动**: 
+  1. 远端宿主机 `user@192.168.2.79`(ThinkPad T440p)休眠配置彻底禁用:通过 systemd mask 屏蔽 `sleep.target`、`suspend.target`、`hibernate.target`、`hybrid-sleep.target`;并在 `/etc/systemd/logind.conf.d/disable-sleep.conf` 中忽略合盖、电源键、待机动作;同时配置 GNOME 用户级电源参数,杜绝断电或空闲休眠;
+  2. 部署容错升级版 `tools/remote_flash_cpld.py` 至 `/home/user/flash_cpld.py`,支持 Tcl catch 容错即时退出,支持 FT232 串口芯片识别与免等待烧录;
+  3. 执行 `python3 /home/user/flash_cpld.py burn /home/user/prod2u_6400_v2.bit`,将原生 Anlogic TD 2026.1 SP2 编译的 `prod2u_6400_v2.bit` 烧入板载 SPI Flash 并刷新 CPLD 运行。
+- **现象**: 
+  1. 用户插接 JTAG 调试排线瞬间笔记本休眠断网,网关返回 `Destination Host Unreachable`;
+  2. 重新连接恢复后,初始读取 JTAG 报 `PRG-9525 ERROR: Chip validation failed`,排查为主板未供电或接触未就绪;就绪后报 `Connect device: EF2L45`;
+  3. 串口在 115200 波特率下接收为非 ASCII 的连续 `0xFB` 字节。
+- **根因**: 
+  1. ThinkPad 笔记本默认开启合盖和无交流供电自动休眠机制;
+  2. 6400 V2.0 顶层 `host_uart_endpoint` 的参数 `CLKS_PER_BIT` 默认为 27(对应 25MHz 下的 921600 波特率),以 115200 监听产生波特率不匹配乱码。
+- **修复**: 
+  1. 彻底禁用系统所有休眠、合盖挂起与低电量自动休眠;
+  2. 在 `192.168.2.79` 上使用 921600 波特率与板卡通信,捕获到标准的 `A5 5A 51 00 81 20` 信标帧;
+  3. 构造 921600 波特率下的原生单行 Bash 指令(`stty` + `printf` 逃逸字节)及 Python 原生串口命令,下发 4 腔体 10%~60% PTC 及风扇占空比。
+- **验证**:
+  1. SPI Flash 烧录验证:TD 烧录耗时 21.8 秒,校验显示 `Chip validation success: EF2L45`,Flash 烧录并刷新成功;
+  2. 串口信标捕获:实时抓取到空闲 5 秒周期发送的信标帧 `A5 5A 51 00 81 20`;
+  3. 指令下发与应答验证:通过 Bash 下发 4 腔体 PTC 10~60%、风扇 10~40% 的 `SET_ALL` 帧(CRC `0x3743`),板卡即时返回 `A5 5A 81 00 A6 35`(`SET_ACK`);
+  4. 寄存器生效回读:下发 `GET_ALL`(`A5 5A 02 00 6D 7B`),读取到 `GET_DATA` 帧,实际生效 PTC 24 通道精确为 `[10, 20, 30, 40, 50, 60] * 4`,风扇通道精确为 `[10, 20, 30, 40]` 与 `[10, 20, 30, 40]`,100% 闭环匹配。

+ 144 - 0
tools/remote_flash_cpld.py

@@ -0,0 +1,144 @@
+#!/usr/bin/env python3
+import sys
+import os
+import time
+import subprocess
+import argparse
+
+TD_BW = '/home/user/td/bin/bw.sh'
+
+def run_tcl(script_content):
+    tcl_file = '/tmp/_tmp_bw_script.tcl'
+    with open(tcl_file, 'w') as f:
+        f.write(script_content)
+    try:
+        res = subprocess.run([TD_BW, tcl_file], capture_output=True, text=True, timeout=60)
+        return res.returncode, res.stdout, res.stderr
+    except Exception as e:
+        return -1, '', str(e)
+    finally:
+        if os.path.exists(tcl_file):
+            try:
+                os.remove(tcl_file)
+            except OSError:
+                pass
+
+def cmd_check():
+    print('=== 1. Checking USB Devices ===')
+    lsusb = subprocess.run(['lsusb'], capture_output=True, text=True).stdout
+    anlogic_cable = '336c:1002' in lsusb
+    serial_ok = ('1a86:7523' in lsusb) or ('0403:6001' in lsusb)
+    print(f'Anlogic Programmer (336c:1002): {"FOUND [OK]" if anlogic_cable else "NOT FOUND [FAIL]"}')
+    print(f'Serial Port (CH340/FT232):       {"FOUND [OK]" if serial_ok else "NOT FOUND [FAIL]"}')
+    
+    print('\n=== 2. Checking JTAG Cable & CPLD Device ===')
+    tcl = """
+set ret [catch {list_cable} out]
+set ret2 [catch {read_device_id} dev]
+puts "DEVICE_DETECTED: $dev"
+exit
+"""
+    code, stdout, stderr = run_tcl(tcl)
+    detected = False
+    for line in stdout.splitlines():
+        if 'Connect device:' in line or 'DEVICE_DETECTED:' in line or 'ERROR' in line:
+            print(line)
+        if 'EF2L45' in line:
+            detected = True
+    if detected:
+        print('\n>>> CPLD EF2L45 Detected Successfully! Hardware is READY! <<<')
+    else:
+        print('\n>>> Device not detected or Chip validation failed. Check cable connection & board power. <<<')
+
+def cmd_burn(bit_file):
+    bit_path = os.path.abspath(bit_file)
+    if not os.path.exists(bit_path):
+        print(f'Error: File not found: {bit_path}')
+        sys.exit(1)
+    print(f'=== Burning {bit_path} to CPLD SPI Flash ===')
+    tcl = f"""
+catch {{download -mode program_spi -bit "{bit_path}"}} err1
+puts "PROG_RES: $err1"
+catch {{download -mode refresh -bit "{bit_path}"}} err2
+puts "REFRESH_RES: $err2"
+exit
+"""
+    t0 = time.time()
+    code, stdout, stderr = run_tcl(tcl)
+    t1 = time.time()
+    
+    success = 'Chip validation success: EF2L45' in stdout and 'finish command "download -mode refresh' in stdout
+    if success:
+        print(f'\n>>> SUCCESS: Firmware burned and chip refreshed in {t1-t0:.1f}s! <<<')
+    else:
+        print('\n>>> FAILED: Burning process encountered an issue. Output log: <<<')
+        print(stdout)
+        if stderr:
+            print('STDERR:', stderr)
+
+def cmd_sram(bit_file):
+    bit_path = os.path.abspath(bit_file)
+    if not os.path.exists(bit_path):
+        print(f'Error: File not found: {bit_path}')
+        sys.exit(1)
+    print(f'=== Downloading {bit_path} to CPLD volatile SRAM ===')
+    tcl = f"""
+catch {{download -mode jtag -bit "{bit_path}"}} err
+puts "JTAG_RES: $err"
+exit
+"""
+    t0 = time.time()
+    code, stdout, stderr = run_tcl(tcl)
+    t1 = time.time()
+    if 'finish command "download -mode jtag' in stdout:
+        print(f'>>> SUCCESS: Downloaded to SRAM in {t1-t0:.2f}s! <<<')
+    else:
+        print('>>> FAILED: Download to SRAM failed: <<<')
+        print(stdout)
+
+def cmd_uart(baud, duration):
+    import serial
+    print(f'=== Listening to /dev/ttyUSB0 at {baud} baud for {duration} seconds ===')
+    try:
+        s = serial.Serial('/dev/ttyUSB0', baud, timeout=0.5)
+    except Exception as e:
+        print(f'Error opening serial port: {e}')
+        return
+    t0 = time.time()
+    total_bytes = 0
+    while time.time() - t0 < duration:
+        b = s.read(128)
+        if b:
+            total_bytes += len(b)
+            print(f'[{len(b)} B] HEX: {b.hex()} | ASCII: {b.decode("latin1", errors="replace")}')
+    s.close()
+    print(f'=== Finished: received {total_bytes} bytes total ===')
+
+def main():
+    parser = argparse.ArgumentParser(description='CPLD EF2L45 Remote Flash & Test Tool')
+    subparsers = parser.add_subparsers(dest='command', required=True)
+    
+    subparsers.add_parser('check', help='Check cable and detect CPLD chip')
+    
+    p_burn = subparsers.add_parser('burn', help='Burn bitstream to non-volatile SPI Flash')
+    p_burn.add_argument('file', help='Path to .bit bitstream file')
+    
+    p_sram = subparsers.add_parser('sram', help='Download bitstream to volatile SRAM')
+    p_sram.add_argument('file', help='Path to .bit bitstream file')
+    
+    p_uart = subparsers.add_parser('uart', help='Listen to CPLD serial port /dev/ttyUSB0')
+    p_uart.add_argument('--baud', type=int, default=115200, help='Baud rate (default 115200)')
+    p_uart.add_argument('--duration', type=float, default=3.0, help='Listening duration in seconds')
+
+    args = parser.parse_args()
+    if args.command == 'check':
+        cmd_check()
+    elif args.command == 'burn':
+        cmd_burn(args.file)
+    elif args.command == 'sram':
+        cmd_sram(args.file)
+    elif args.command == 'uart':
+        cmd_uart(args.baud, args.duration)
+
+if __name__ == '__main__':
+    main()