diff --git a/scripts/program_device.sh b/scripts/program_device.sh new file mode 100755 index 0000000..d8d4160 --- /dev/null +++ b/scripts/program_device.sh @@ -0,0 +1,15 @@ +#!/usr/bin/bash + +THISSCRIPT=$(realpath $0) +PROJECT_ROOT=$(dirname $(dirname $THISSCRIPT)) +TCLSCRIPT="$PROJECT_ROOT/tcl/program_device.tcl" + +if [ $# -lt 1 ]; then + echo "Usage: $0 BITFILE" + exit -1 +fi + +BITFILE=$1 + +$VIVADO_ROOT/bin/vivado -mode batch -source "$TCLSCRIPT" -tclargs "$BITFILE" + diff --git a/tcl/program_device.tcl b/tcl/program_device.tcl new file mode 100644 index 0000000..b37b52c --- /dev/null +++ b/tcl/program_device.tcl @@ -0,0 +1,39 @@ +if { $argc < 1 } { + puts "Usage: program_device.sh BITFILE" + exit -1 +} + +set bitfile [lindex $argv 0] + +set hwserver "localhost:3121" +set hwtarget "$hwserver/*" + +puts "Opening hardware server at $hwserver" + +open_hw_manager +connect_hw_server -url $hwserver + +puts "Opening target $hwtarget" + +set targetlist [get_hw_targets $hwtarget] +if { [llength $targetlist] != 1 } { + puts "Failed to get hw target. Number of matching targets is not 1." + exit -2 +} + +set target $targetlist + +current_hw_target $target +open_hw_target + +puts "Refreshing device" +refresh_hw_device [current_hw_device] + +puts "Programming device using bitfile $bitfile" +set_property PROGRAM.file "$bitfile" [current_hw_device] +program_hw_devices [current_hw_device] +refresh_hw_device [current_hw_device] + +puts "Successfully programmed device" +exit 0 +