Skip to content

Instantly share code, notes, and snippets.

@yashi
Last active April 26, 2023 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashi/32cb88e7b6935283e9a4b5194c76bc4b to your computer and use it in GitHub Desktop.
Save yashi/32cb88e7b6935283e9a4b5194c76bc4b to your computer and use it in GitHub Desktop.
Write .bit to FPGA or .mcs to on-board SPI NOR flash memory
#!/bin/sh
#
# (C) Copyright 2023 Space Cubics, LLC
#
# Make the next line a comment line for TCL \
exec vivado -mode batch -nolog -nojournal -notrace -tempDir $(mktemp -d /tmp/vivado.XXXXXXXXXX) -source "$0" -tclargs ${1+"$@"}
set cfgmem_mode [string match "*cfgmem*" $argv0]
# Set device parameter
set xil_device xc7a200t_0
set cfg_memory s25fl256l-spi-x1_x2_x4
set the_file [lindex $argv 0]
if { ! [file exists $the_file] } {
puts [format "Specified file '%s' does not exist" $the_file]
exit
}
# Open hw manager, hw server, and the target
open_hw_manager
connect_hw_server
open_hw_target
# Select the device, set a program file for the device
current_hw_device ${xil_device}
# Setup the configuration memory and prepare
if {$cfgmem_mode} {
create_hw_cfgmem -hw_device [current_hw_device] ${cfg_memory}
set_property PROGRAM.UNUSED_PIN_TERMINATION {pull-none} [current_hw_cfgmem]
set_property PROGRAM.ADDRESS_RANGE {use_file} [current_hw_cfgmem]
set_property PROGRAM.ERASE true [current_hw_cfgmem]
set_property PROGRAM.BLANK_CHECK false [current_hw_cfgmem]
set_property PROGRAM.CFG_PROGRAM true [current_hw_cfgmem]
set_property PROGRAM.VERIFY true [current_hw_cfgmem]
set_property PROGRAM.CHECKSUM false [current_hw_cfgmem]
set_property PROGRAM.PRM_FILE {} [current_hw_cfgmem]
program_hw_devices [current_hw_device]
}
# Program the target
if {$cfgmem_mode} {
set_property PROGRAM.FILES ${the_file} [current_hw_cfgmem]
program_hw_cfgmem [current_hw_cfgmem]
} else {
set_property PROGRAM.FILE ${the_file} [current_hw_device]
program_hw_devices [current_hw_device]
}
# Shut it down
close_hw_target
disconnect_hw_server
close_hw_manager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment