目录
1. 简介
1.1 ChipScoPy
Target Communication Framework
ChipScoPy 是一个开源 Python 项目,用于与 Xilinx Versal 硬件调试解决方案进行通信和控制。客户端 Python 脚本可以访问丰富的硬件交互 API。ChipScoPy 包的主要功能包括:
- Device detection, programming, and status
- Memory subsystems support
- Fabric Debug Core support
- Integrated Logic Analyzer (ILA)
- Virtual Input Output (VIO)
- Hardened Core support
- DDR Memory Controller (DDRMC)
- Integrated Bit Error Ratio Tester (IBERT)
- System Monitor (SysMon)
- Network on Chip Performance Monitor (NoC PerfMon)
- PCI Express (PCIe)
1.2 XSDB
XSDB(Xilinx System Debugger,系统调试器)使用 HW Server 作为底层调试引擎,提供了一种通过 JTAG 接口与 Xilinx 硬件系统进行交互的命令行调试工具。可以将用户界面操作转换为一系列目标通信框架 (TCF) 命令。
关于 XSCT:
XSCT (Xilinx Software Command-Line Tool) 是一个更高级的命令行工具,它包含了 XSDB 的所有功能,并且还提供了一些额外的功能,例如工程管理、构建和下载等。
如果在 bash 中启动 xsct,会出现如下提示:
Warning: XSCT is deprecated and will be removed in future releases.
We recommend using the new Python command-line tool for project management and debugging:
- Run "vitis -i" for interactive mode.
- Run "vitis -s <script>" for script mode.
XSCT 已经被标记为 “deprecated”(不推荐使用),并且在未来的版本中会被移除。
1.3 Python CLI
Python CLI 实际上指的是在新的 Vitis 命令行工具中使用 Python 脚本来执行以前通过 XSCT 和 XSDB 完成的调试任务。由于 XSCT 正在被弃用,Xilinx 转向了基于 Python 的方法。
核心概念:
- Vitis 命令行工具: 这是取代 XSCT 的新工具,使用 vitis 命令启动。
- Python API: Vitis 命令行工具基于 Python API 构建,也就是需要使用 Python 语法来编写脚本,而不是之前的 Tcl。
- xsdb 模块: 在 Vitis Python API 中,有一个 xsdb 模块,它提供了与 XSDB 功能相对应的 Python 函数。这个模块让你能够通过 Python 脚本执行各种调试操作。
2. 安装 ChipScoPy
2.1 Python 环境
官方建议使用的版本 Python 3.8、3.9、3.10、3.11、3.12。
有多种方法可以配置使用 ChipScoPy API。
本文分享使用 conda 来管理虚拟环境,并使用ChipScPy。
启用 conda:
>> cd /opt/anaconda3/bin/
>> ./conda init bash
(base)>> conda --version # 确认已启用conda,并查看conda版本
(base)>> python --version # 查看python版本
区分,在 conda 与 shell 中查看 python 版本并不一致:
>> python3 --version
2.2 设置虚拟环境
1)创建 scopy 虚拟环境:
conda deactivate # 激活 base 环境(如果需要)
conda create -n scopy python=3.12.7 # 创建虚拟环境 scopy
conda activate scopy # 激活虚拟环境 scopy
创建虚拟环境 scopy 时,需要指定 python 版本(当前conda的base环境python=3.12.7),不指定的话,conda 会直接使用最新版本(下载新的python=3.13.1)。
2)查看所有已创建的虚拟环境
conda env list
conda info --envs
conda create -n new_env --clone old_env # 克隆旧环境
2)删除 scopy 虚拟环境,并清除与其关联的所有包:
conda remove --name scopy --all
2.3 安装 ChipScoPy
1)激活 scopy 虚拟环境
(base)>> conda activate scopy
---
(scopy)>>
2)安装 ChipScoPy 包
由于 conda 仓库中并没有 ChipScoPy 包,需要使用 python pip 来安装
(scopy)>> python -m pip install --upgrade pip # 更新 pip
(scopy)>> python -m pip install 'chipscopy==2024.2.*' # 安装指定版本的chipscopy
---
Successfully installed Click-8.1.8 antlr4-python3-runtime-4.13.1 certifi-2024.12.14 charset-normalizer-3.4.1 chipscopy-2024.2.1733027508 idna-3.10 importlib_metadata-6.11.0 loguru-0.7.3 markdown-it-py-3.0.0 mdurl-0.1.2 more-itertools-10.5.0 pygments-2.19.1 requests-2.32.3 rich-13.9.4 typing_extensions-4.12.2 urllib3-2.3.0 zipp-3.21.0
2.4 安装依赖
运行以下命令来安装附加支持包:
(scopy)>> python -m pip install chipscopy[core-addons]
(scopy)>> python -m pip install chipscopy[jupyter]
有如下报错:
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [6 lines of output]
Cargo, the Rust package manager, is not installed or is not on PATH.
This package requires Rust and Cargo to compile extensions. Install it through
the system's package manager or via https://rustup.rs/
Checking for Rust toolchain....
[end of output]
解决办法,安装 rust:
(scopy)>> curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
直接按 Enter 键接受默认选项即可。
(scopy)>> source ~/.cargo/env
验证 Rust 和 Cargo 是否安装成功:
(scopy)>> rustc --version
(scopy)>> cargo --version
然后再次执行安装:
(scopy)>> python -m pip install chipscopy[jupyter]
2.5 安装示例
有一个脚本可将示例安装到用户选择的特定目录中。
(scopy)>> chipscopy-get-examples
---
chipscopy-get-examples
No examples available locally, they will be downloaded from Github.
Do you want to proceed? [Y/n] y
Downloading examples from https://github.com/Xilinx/chi