| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- #!/usr/bin/env python3
- """Automated sync of latest codebase and verified firmware to Windows delivery directory.
- Target: C:\\Users\\Administrator\\Desktop\\prod2u-delivery on 192.168.2.24
- """
- import hashlib
- import json
- import os
- from pathlib import Path
- import subprocess
- import sys
- import tarfile
- import zipfile
- WIN_HOST = "administrator@192.168.2.24"
- WIN_BASE_DIR = "C:/Users/Administrator/Desktop/prod2u-delivery"
- ROOT = Path(__file__).resolve().parent.parent
- BITSTREAM_MRDIMM = Path("/data/prod2u/cpld-runs/mrdimm-chamber-td-20261009T072939Z-e6d2bdb6/bitgen/prod2u_mrdimm.bit")
- RECEIPT_MRDIMM = Path("/data/prod2u/cpld-runs/mrdimm-chamber-td-20261009T072939Z-e6d2bdb6/td-receipt.json")
- BITSTREAM_6400_V2 = Path("/data/prod2u/cpld-runs/6400-v2-td-20261009T073224Z-e6d2bdb6/bitgen/prod2u_6400_v2.bit")
- RECEIPT_6400_V2 = Path("/data/prod2u/cpld-runs/6400-v2-td-20261009T073224Z-e6d2bdb6/td-receipt.json")
- HW_RECEIPT = ROOT / "receipts/hardware_test_receipt.json"
- def sha256_file(path: Path) -> str:
- h = hashlib.sha256()
- with open(path, "rb") as f:
- while chunk := f.read(65536):
- h.update(chunk)
- return h.hexdigest()
- def run_ssh(cmd: str, check: bool = True) -> subprocess.CompletedProcess:
- res = subprocess.run(["ssh", "-o", "StrictHostKeyChecking=no", WIN_HOST, cmd], capture_output=True, text=True)
- if check and res.returncode != 0:
- raise RuntimeError(f"SSH command failed ({res.returncode}):\nCmd: {cmd}\nStderr: {res.stderr}\nStdout: {res.stdout}")
- return res
- def scp(local: Path, remote: str):
- print(f"Uploading {local.name} -> {remote}...")
- subprocess.run(["scp", "-o", "StrictHostKeyChecking=no", str(local), f"{WIN_HOST}:{remote}"], check=True)
- def main():
- print("=== Step 1: Packaging latest clean codebase ===")
- tar_path = Path("/tmp/cpld-temperature-control-latest.tar.gz")
- zip_path = Path("/tmp/cpld-temperature-control-latest.zip")
-
- exclude_dirs = {'.git', '.cache', '__pycache__', '.pytest_cache', 'scratch', 'dist', '.omo', 'tmp', 'cpld-runs'}
- exclude_exts = {'.pyc', '.o', '.db', '.log'}
-
- def is_valid(p: Path):
- if any(part in exclude_dirs for part in p.parts):
- return False
- if p.suffix in exclude_exts:
- return False
- return True
- # Build tar.gz (for extracting into latest-code/)
- with tarfile.open(tar_path, 'w:gz') as tar:
- for path in sorted(ROOT.rglob('*')):
- if not path.is_file() or not is_valid(path):
- continue
- rel = path.relative_to(ROOT)
- tar.add(path, arcname=str(Path('latest-code') / rel))
-
- # Build zip (for user direct download)
- with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as z:
- for path in sorted(ROOT.rglob('*')):
- if not path.is_file() or not is_valid(path):
- continue
- rel = path.relative_to(ROOT)
- z.write(path, arcname=str(Path('cpld-temperature-control') / rel))
-
- print(f"Tar size: {tar_path.stat().st_size / 1024 / 1024:.2f} MB")
- print(f"Zip size: {zip_path.stat().st_size / 1024 / 1024:.2f} MB")
- zip_sha = sha256_file(zip_path)
-
- print("\n=== Step 2: Uploading codebase to Windows ===")
- scp(zip_path, f"{WIN_BASE_DIR}/cpld-temperature-control-latest.zip")
-
- # Extract zip into cpld-temperature-control directory
- print("Extracting cpld-temperature-control directory on Windows...")
- run_ssh(f'cd /d "{WIN_BASE_DIR}" && powershell -NoProfile -Command "Expand-Archive -Path cpld-temperature-control-latest.zip -DestinationPath . -Force"')
-
- print("\n=== Step 3: Updating MRDIMM-V1.2 and 6400-V2.0 firmware ===")
- assert BITSTREAM_MRDIMM.is_file(), f"Missing {BITSTREAM_MRDIMM}"
- mrdimm_sha = sha256_file(BITSTREAM_MRDIMM)
- print(f"MRDIMM bitstream SHA256: {mrdimm_sha}")
- scp(BITSTREAM_MRDIMM, f"{WIN_BASE_DIR}/MRDIMM-V1.2/prod2u_mrdimm.bit")
- scp(BITSTREAM_MRDIMM, f"{WIN_BASE_DIR}/MRDIMM-V1.2/firmware/prod2u_mrdimm.bit")
- scp(RECEIPT_MRDIMM, f"{WIN_BASE_DIR}/MRDIMM-V1.2/firmware/TD-BUILD-RECEIPT.json")
- assert BITSTREAM_6400_V2.is_file(), f"Missing {BITSTREAM_6400_V2}"
- v2_sha = sha256_file(BITSTREAM_6400_V2)
- print(f"6400 V2.0 bitstream SHA256: {v2_sha}")
- scp(BITSTREAM_6400_V2, f"{WIN_BASE_DIR}/6400-V2.0/prod2u_6400_v2.bit")
- scp(BITSTREAM_6400_V2, f"{WIN_BASE_DIR}/6400-V2.0/firmware/prod2u_6400_v2.bit")
- scp(RECEIPT_6400_V2, f"{WIN_BASE_DIR}/6400-V2.0/firmware/TD-BUILD-RECEIPT.json")
- if HW_RECEIPT.is_file():
- scp(HW_RECEIPT, f"{WIN_BASE_DIR}/MRDIMM-V1.2/firmware/hardware_test_receipt.json")
- scp(HW_RECEIPT, f"{WIN_BASE_DIR}/hardware_test_receipt.json")
- print("\n=== Step 4: Creating and Uploading Analysis Package ===")
- analysis_zip = Path("/tmp/Prod2U-Analysis.zip")
- with zipfile.ZipFile(analysis_zip, 'w', zipfile.ZIP_DEFLATED) as az:
- # Include audit and decision reports
- for rep in ["REAUTH-SOURCE-AUTHORITY.json", "REAUTH-SOURCE-AUTHORITY.md", "AUTHORITY-CONFLICTS.md",
- "baud-decision.json", "baud-decision.md", "VERSION.json", "AGENTS.md", "RECOVERY_STATE.md"]:
- rp = ROOT / rep
- if rp.is_file():
- az.write(rp, arcname=f"audit_reports/{rep}")
- # Include receipts
- if RECEIPT_MRDIMM.is_file():
- az.write(RECEIPT_MRDIMM, arcname="receipts/mrdimm_td_receipt.json")
- if RECEIPT_6400_V2.is_file():
- az.write(RECEIPT_6400_V2, arcname="receipts/6400_v2_td_receipt.json")
- if HW_RECEIPT.is_file():
- az.write(HW_RECEIPT, arcname="receipts/hardware_test_receipt.json")
- # Include contracts
- for cp in ROOT.glob("contracts/**/*"):
- if cp.is_file():
- az.write(cp, arcname=f"contracts/{cp.relative_to(ROOT / 'contracts')}")
- # Include source trees
- for sp in ROOT.glob("src/**/*"):
- if sp.is_file():
- az.write(sp, arcname=f"src/{sp.relative_to(ROOT / 'src')}")
- for tp in ROOT.glob("tests/**/*"):
- if tp.is_file():
- az.write(tp, arcname=f"tests/{tp.relative_to(ROOT / 'tests')}")
- analysis_sha = sha256_file(analysis_zip)
- print(f"Prod2U-Analysis.zip size: {analysis_zip.stat().st_size / 1024 / 1024:.2f} MB, SHA256: {analysis_sha}")
- scp(analysis_zip, f"{WIN_BASE_DIR}/Prod2U-Analysis.zip")
- print("\n=== Step 5: Updating manifests, changelog and readmes ===")
- changelog_content = """Prod2U 交付变更与维护记录 (CHANGELOG)
- ================================================================================
- 【2026-10-09 最新发布:MRDIMM-V1.2 / 6400 V2.0 来源重新认证、精简稳定化与双向实机闭环交付】
- 1. 规范更新与工业要求固化:
- - 确定并固化 VERSION.json 为 PROD2U-MIN-20261009.r1。
- - 生产业务固件就绪后,周期性(每 500ms)自主向 Host UART 广播包含前导方波同步头、ASCII 状态横幅
- [PROD2U MRDIMM-V1.2 OK] 与标准协议信标帧 (A5 5A 51 00 81 20 \\r\\n) 的调试数据包。
- - 确定 Host UART 物理通信默认波特率为 115200 8N1(参数化 CLKS_PER_BIT = 217),消除
- 常规串口线(如 CH340 芯片 12MHz 晶振)在 921600 下 -18.6% 的物理硬件时钟误差。
- - 6400 V2.0 独占时钟/约束闭包与温度写仲裁 FIFO 队列(支持 N..N+4 级突发 CT 写入防冲突)。
- 2. 生产 RTL 顶层与自主调试引擎升级:
- - 新增独立自主调试引擎 src/common/prod2u_active_debug_engine.v。
- - 在正式生产顶层 prod2u_mrdimm_final_top.v 中无缝集成该引擎,在串口空闲时自主播发调试数据,
- 同时与上位机主从交互(SET_ALL / GET_ALL / MOTOR_DONE)实现零冲突仲裁,主机响应优先。
- - 6400 V2.0 顶层 prod2u_6400_v2_top.v 集成 4 深度 CT 写缓冲 FIFO 与 overflow 告警,彻底避免多源写冲突。
- - 通过安路 TD 2026.1 SP2 全流程编译:
- * MRDIMM V1.2: LUT 4339 / 4480 (< 4480 物理上限), Setup Slack +18.20ns, Hold Slack +0.038ns, Fmax 45.88MHz
- 位流 SHA256: f59caf36124d9834aa6587928be84a4cddbc081c93bf2b38343e9f724bd9b212
- * 6400 V2.0: LUT 2204 / 4480 (< 4480 物理上限), Setup Slack +25.99ns, Hold Slack +0.038ns, Fmax 71.41MHz
- 位流 SHA256: 29c56a60c72232e0168df5c9a56b27e2ab2e58ed80f08a7e009b1ca43f7d3b7f
- 3. 物理板卡 Flash 刷写与串口收发实测闭环:
- - 在 user@192.168.2.79 实体板卡上完成 SRAM 与 SPI Flash 刷写验证。
- - 物理串口执行 7 阶段全链路测试(HEARTBEAT / GET_ALL 默认值 / SET_ALL 动作与 MOTOR_DONE /
- GET_ALL 生效值 / STOP_CLEAR / 30 秒看门狗超时回退 / 看门狗后直接恢复),100% 通过!
- 4. 最新工程源代码与发布包同步维护:
- - 交付目录根目录下同步 "cpld-temperature-control\\" 完整最新源码解压目录与最新压缩包。
- - 提供 "Prod2U-Analysis.zip" 包含所有测试回执、时序报告与认证文档。
- ================================================================================
- """
- tmp_changelog = Path("/tmp/CHANGELOG.txt")
- tmp_changelog.write_text(changelog_content, encoding="utf-8")
- scp(tmp_changelog, f"{WIN_BASE_DIR}/CHANGELOG.txt")
- readme_content = """===============================================================================
- Prod2U 交付系统使用说明 (最新维护日期: 2026-10-09)
- ===============================================================================
- 【最新工程源代码位置】
- 1. 完整最新代码解压目录:
- -> "cpld-temperature-control\\"
- 2. 最新代码单体压缩包:
- -> "cpld-temperature-control-latest.zip"
- 3. 全套代码与证据分析包:
- -> "Prod2U-Analysis.zip"
- 【产品运行入口 (用户直接双击运行)】
- 1. 6400 V1.1 温度控制系统:
- -> 进入 "6400-V1.1" 目录,双击运行 "Prod2U-6400-GUI.exe"
- -> 对应固件: prod2u_6400_front_back.bit
- 2. 6400 V2.0 温度控制系统:
- -> 进入 "6400-V2.0" 目录,双击运行 "Prod2U-6400-V2-GUI.exe"
- -> 对应固件: prod2u_6400_v2.bit (SHA256: 29c56a60c72232e0168df5c9a56b27e2ab2e58ed80f08a7e009b1ca43f7d3b7f)
- 3. MRDIMM V1.2 腔体控制系统:
- -> 进入 "MRDIMM-V1.2" 目录,双击运行 "Prod2U-MRDIMM-GUI.exe"
- -> 对应固件: prod2u_mrdimm.bit (SHA256: f59caf36124d9834aa6587928be84a4cddbc081c93bf2b38343e9f724bd9b212)
- * 默认波特率 115200 8N1,周期性自主发送 [PROD2U MRDIMM-V1.2 OK] 状态横幅。
- ===============================================================================
- """
- tmp_readme = Path("/tmp/README.txt")
- tmp_readme.write_text(readme_content, encoding="utf-8")
- scp(tmp_readme, f"{WIN_BASE_DIR}/README.txt")
- scp(tmp_readme, f"{WIN_BASE_DIR}/使用说明.txt")
- manifest_data = {
- "schema": "prod2u-delivery-manifest-v4",
- "generated_at": "2026-10-09T07:45:00Z",
- "version": "PROD2U-MIN-20261009.r1",
- "latest_source": {
- "directory": "cpld-temperature-control",
- "zip_archive": "cpld-temperature-control-latest.zip",
- "zip_sha256": zip_sha,
- "analysis_zip": "Prod2U-Analysis.zip",
- "analysis_sha256": analysis_sha
- },
- "products": {
- "6400-V2.0": {
- "bitstream": "prod2u_6400_v2.bit",
- "bitstream_sha256": v2_sha,
- "status": "TD_PASS"
- },
- "MRDIMM-V1.2": {
- "bitstream": "prod2u_mrdimm.bit",
- "bitstream_sha256": mrdimm_sha,
- "status": "TD_PASS_AND_HARDWARE_PASS"
- }
- }
- }
- tmp_manifest = Path("/tmp/DELIVERY-MANIFEST.json")
- tmp_manifest.write_text(json.dumps(manifest_data, indent=2, ensure_ascii=False), encoding="utf-8")
- scp(tmp_manifest, f"{WIN_BASE_DIR}/DELIVERY-MANIFEST.json")
- print("\n=== Step 6: Remote PowerShell SHA-256 Validation ===")
- ps_cmd = (
- f"$h1 = (Get-FileHash -Path '{WIN_BASE_DIR}/cpld-temperature-control-latest.zip' -Algorithm SHA256).Hash.ToLower(); "
- f"$h2 = (Get-FileHash -Path '{WIN_BASE_DIR}/Prod2U-Analysis.zip' -Algorithm SHA256).Hash.ToLower(); "
- f"$h3 = (Get-FileHash -Path '{WIN_BASE_DIR}/MRDIMM-V1.2/prod2u_mrdimm.bit' -Algorithm SHA256).Hash.ToLower(); "
- f"$h4 = (Get-FileHash -Path '{WIN_BASE_DIR}/6400-V2.0/prod2u_6400_v2.bit' -Algorithm SHA256).Hash.ToLower(); "
- f"Write-Output ('ZIP:' + $h1 + ' ANALYSIS:' + $h2 + ' MRDIMM:' + $h3 + ' M6400:' + $h4)"
- )
- res = run_ssh(f'powershell -NoProfile -Command "{ps_cmd}"')
- print("Remote Hashes:", res.stdout.strip())
- assert f"ZIP:{zip_sha.lower()}" in res.stdout, "Zip SHA mismatch"
- assert f"ANALYSIS:{analysis_sha.lower()}" in res.stdout, "Analysis Zip SHA mismatch"
- assert f"MRDIMM:{mrdimm_sha.lower()}" in res.stdout, "MRDIMM bitstream SHA mismatch"
- assert f"M6400:{v2_sha.lower()}" in res.stdout, "6400 V2.0 bitstream SHA mismatch"
- print("\n=== SUCCESS: All artifacts uploaded, verified with remote PowerShell SHA-256! ===")
- if __name__ == "__main__":
- main()
|