- fpga_flash: 新增 build_zynq_boot.py / program_zynq_qspi.py(bootgen + program_flash, 含备份、SHA-256/容量/marker 守卫);vivado_env.py 增 resolve_sdk_dir(SDK_ROOT/SDK_PATH); SKILL.md 补 Zynq 烧写流程,示例去掉写死的 D:\Xilinx\SDK\2018.1,改由 skills_env.md 解析。 - rtl-ip-replace: gen_ip.tcl / namespace_ip.py 更新。 - sim-rtl-flow: SKILL.md 与 run_sim_rtl_flow.py 更新。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
79 lines
2.5 KiB
Python
79 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Resolve the machine-local Vivado install path.
|
|
|
|
The install path differs per machine (C:\\Xilinx here, D:\\Xilinx elsewhere), so it
|
|
is never hardcoded in a skill. It lives in ~/skills_env.md, which stays out of git.
|
|
Precedence: explicit --vivado-dir > OS env var > ~/skills_env.md.
|
|
"""
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
|
|
def env_lookup(key, default=None):
|
|
"""Read KEY from the OS environment, else from a `KEY = value` line in
|
|
~/skills_env.md. Trailing `# comments` are stripped."""
|
|
v = os.environ.get(key)
|
|
if v:
|
|
return v
|
|
path = os.path.join(os.path.expanduser("~"), "skills_env.md")
|
|
try:
|
|
with open(path, encoding="utf-8") as f:
|
|
for line in f:
|
|
m = re.match(rf"\s*{re.escape(key)}\s*=\s*(.+?)\s*(?:#.*)?$", line)
|
|
if m:
|
|
val = m.group(1).strip()
|
|
# Placeholders like `<未安装>` mean "not configured on this machine".
|
|
if val and not val.startswith("<"):
|
|
return val
|
|
except OSError:
|
|
pass
|
|
return default
|
|
|
|
|
|
def resolve_vivado_dir(cli_value=None):
|
|
"""Vivado install ROOT (the dir containing bin/vivado.bat)."""
|
|
if cli_value:
|
|
return cli_value
|
|
root = env_lookup("VIVADO_ROOT")
|
|
if root:
|
|
return root
|
|
exe = env_lookup("VIVADO_PATH")
|
|
if exe:
|
|
# .../<root>/bin/vivado.bat -> <root>
|
|
return os.path.dirname(os.path.dirname(exe))
|
|
sys.exit(
|
|
"Vivado path not configured. Add `VIVADO_ROOT = <install root>` to "
|
|
"~/skills_env.md, set it as an env var, or pass --vivado-dir."
|
|
)
|
|
|
|
|
|
def resolve_vivado_exe(cli_value=None):
|
|
"""Full path to bin/vivado.bat."""
|
|
if cli_value:
|
|
return cli_value
|
|
exe = env_lookup("VIVADO_PATH")
|
|
if exe:
|
|
return exe
|
|
return os.path.join(resolve_vivado_dir(), "bin", "vivado.bat")
|
|
|
|
|
|
def resolve_sdk_dir(cli_value=None):
|
|
"""Xilinx SDK install ROOT (the dir containing bin/bootgen.bat).
|
|
|
|
Precedence matches the Vivado resolver: explicit CLI value, SDK_ROOT,
|
|
SDK_PATH, then the same keys in ~/skills_env.md.
|
|
"""
|
|
if cli_value:
|
|
return cli_value
|
|
root = env_lookup("SDK_ROOT")
|
|
if root:
|
|
return root
|
|
exe = env_lookup("SDK_PATH")
|
|
if exe:
|
|
return os.path.dirname(os.path.dirname(exe))
|
|
sys.exit(
|
|
"Xilinx SDK path not configured. Add `SDK_ROOT = <install root>` to "
|
|
"~/skills_env.md, set it as an env var, or pass --sdk-dir."
|
|
)
|