zynq7000-rs/scripts/zynq7000-ps-pl-init.py

104 lines
3.1 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import os
import subprocess
import sys
from pathlib import Path
# Define the default values
TCL_SCRIPT_NAME = "xsct-init.tcl"
SCRIPTS_DIR = "scripts"
DEFAULT_IP_ADDRESS_HW_SERVER = "localhost"
def main():
parser = argparse.ArgumentParser(
description="Script to launch xsct, initialize and prepare the processing system for debugging "
"and load an a bare-metal application to the board"
)
parser.add_argument(
"-t",
"--tools",
# Required only if env var is not set
required=not bool(os.getenv("VIVADO_TOOLS")),
# Use env var if set
default=os.getenv("VIVADO_TOOLS"),
help="The path to the tool to use. Must point to a valid Vivado tools installation which"
"also provides xsct, for example a Vitis installation. The directory where the path "
" points to should contain a shell script named settings64.sh",
)
parser.add_argument(
"--itcl",
dest="init_tcl",
required=True,
help="Path to the ps7 initialization TCL file to prepare the processing system.",
)
parser.add_argument(
"-a", "--app", required=True, dest="app", help="Path to the app to program"
)
parser.add_argument(
"-i",
"--ip",
default=DEFAULT_IP_ADDRESS_HW_SERVER,
help="The IP address of the hardware server (default: localhost)",
)
parser.add_argument(
"-b",
"--bit",
dest="bit",
help="Optional path to the bitstream which will also be programed to the device.",
)
args = parser.parse_args()
settings_script = os.path.join(args.tools, "settings64.sh")
if not os.path.isfile(settings_script):
print(f"Invalid tool path {args.tools}, did not find settings file.")
sys.exit(1)
# Source the settings script and check for xsdb availability
command = f"source {settings_script} && command -v xsct"
result = subprocess.run(
command,
shell=True,
capture_output=True,
executable="/bin/bash",
)
if result.returncode != 0:
print("Error: 'xsct' could not be found after sourcing settings64.sh.")
sys.exit(1)
if not os.path.isfile(args.app):
print(f"The app '{args.app}' does not exist")
sys.exit(1)
# Export environment variables
os.environ["APP"] = args.app
os.environ["IP_ADDRESS_HW_SERVER"] = args.ip
if args.bit:
os.environ["BITSTREAM"] = args.bit
os.environ["PS_INIT_SCRIPT"] = args.init_tcl
xsct_script = Path(TCL_SCRIPT_NAME)
if not xsct_script.exists():
xsct_script = Path(os.path.join(SCRIPTS_DIR, TCL_SCRIPT_NAME))
if not xsct_script.exists():
print(f"Could not find the xsct initialization script {TCL_SCRIPT_NAME}")
sys.exit(1)
# Launch xsct with the initialization script
command = f"bash -c 'source {settings_script} && xsct {xsct_script} | tee xsct-output.log'"
subprocess.run(
command,
shell=True,
check=True,
)
if __name__ == "__main__":
main()