GitHub Managed Vivado Repositories - barawn/verilog-library-barawn GitHub Wiki
Vivado Projects in GitHub Repositories
This page contains information on setting up and working with GitHub managed Vivado repositories, in the style used by the tclbits "repo_files.tcl" script.
Background
To give a bit of history - Xilinx does not work well with version control. They never have, and I doubt they ever will. Vivado routinely touches internal project files so that virtually everything would need to be updated almost any time a project is opened, and Vitis frighteningly hides fixed paths in its configuration, meaning that any time a collaborator would check something out, the project would immediately stop working. I don't use "frighteningly" lightly in this case, since Vitis is built upon Eclipse, which has great GitHub integration - but attempting to use it with Vitis breaks the entire project.
The most common method I have seen to deal with this is to abandon Vivado project integration entirely and work solely with a command-line build script. I chose not to go this way because for me, I feel that the Vivado project integration speeds my workflow, and it was easier to change Vivado than to abandon those advantages. Because Vivado is built upon Tcl, it is not hard to change it.
Setting Up
As noted in the repo README, you need a Vivado_init.tcl script which replaces the open_project and close_project commands with ones that allow for per-project setup and teardown. An example script is in the repo here.
On Windows, I would also recommend using subst
to create a virtual drive to shorten path lengths as described here.
Under the Hood
The basic ideas behind GitHub managed repositories are:
- Keep the Vivado project in a subdirectory (
vivado_project
) and don't store anything from there (via gitignores). - Keep all sources in their own subdirectories (
ip/
,hdl/
,constraints/
,bd/
,sim/
). - For IPs and block diagrams, store only the descriptions (
.xci
or.bd
) and let Vivado rebuild them, ignoring generated files (via gitignores). - Store the list of files in the Vivado project in tracked files (
sources.txt
,ips.txt
,simulation.txt
,constraints.txt
,simips.txt
). - Automatically check the internal list of files (what Vivado thinks is in the project) against those files at project open (this can be run while the project is open using the
check_all
Tcl command) - Automatically save the internal list of files to those tracked files at project close (this can be run while the project is open using the
save_all
Tcl command). - Change any Vivado project settings via Tcl commands at project open in the
project_init.tcl
script.
Recreating a Managed Repository
- Clone the repository. Make sure to do it recursively as submodules are very common (
git clone --recursive
). - Open Vivado, or if it's already open, close the current project to get to the "welcome screen."
- In the Tcl console, change directories to where you cloned the repository (
cd path/to/repo
). - Source the setup script, typically a Tcl file with the same name as the repository. This creates an empty project and opens it - and with the most recent project creation script, runs the project_init.tcl file to reload all of the sources.
Note: the next step should no longer be necessary for project creation scripts which auto-source the project_init.tcl at the end. You will know if this step is needed if step 4 completes quickly and the project is empty of source files.
- Click the Tcl console table in Vivado, and in the entry window (where it says "Type a Tcl command here") type "source project_init.tcl". This will then take some time as it adds all of the files to the project. Note that previously this step was "close and reopen the project," but you should not do this as it can blow away the source tracking files. If you did this and the source tracking files are all empty, close Vivado and checkout all the ".txt" files in the top directory.
The project is now recreated. Building the project is the same as any other Vivado project. The first build will take quite some time as all of the IP files and block diagrams have to be rebuilt.
Adding Files/IP/Block Diagrams to Managed Repository
Never create a file/constraint/IP/Block Diagram in Vivado's default location ("local to project"). Vivado, by default, stores things in subdirectories underneath its project directory. Source files do not have to be in a specific location in the repository, but a conventional structure (which allows for simple gitignores) would be
hdl/
contains Verilog/VHDL/etc. files used in the implementationsim/
contains Verilog/VHDL/etc. files used in simulation only - testbenches, models, etc. - plus waveconfigs (.wcfg
).ip/
contains.xci
files (each in their own subdirectory) for Vivado IP.bd/
contains block diagram (.bd
) files (each in their own subdirectory).constraints/
contain.xdc
and.tcl
files used as constraints.
The repo_files.tcl
maintenance commands make it easy to identify if you've accidentally created a source file in the default location - just check all of the .txt
files for vivado_project
(e.g. grep "vivado_project" *.txt
).
Changing Build Settings
Whenever you change the build settings in Vivado, you need to make sure those changes are propagated to anyone else using the repository by having them happen in the project_init.tcl
script. For instance, if you change the Verilog include directories, or add scripts that run during steps of the build, or change the build steps or settings.
A lot of these changes can be done using utility functions in the utility.tcl script. For changes that do not have utility functions, just look at what happens in the Tcl console when the settings is changed, and use that Tcl command.
For instance, changing the Route directive to AggressiveExplore results in
set_property STEPS.ROUTE_DESIGN.ARGS.DIRECTIVE AggressiveExplore [get_runs impl_1]
and enabling Post-Route Phys Opt Design results in
set_property STEPS.POST_ROUTE_PHYS_OPT_DESIGN.IS_ENABLED true [get_runs impl_1]
Creating a New Managed Project
To create a new managed project in the simplest way:
- Create a directory named the same as your repository (
this_project/
) - we will call thisrepo_dir
because theproject_init.tcl
template will create a function calledget_repo_dir
which you can call from the Tcl console. - Create a Vivado project in a
vivado_project
subdirectory of the repo_dir (this_project/vivado_project
) as normal. - Run
git init
in the repo_dir. - Run
git submodule add https://github.com/barawn/verilog-library-barawn/
in the repo_dir. - Copy the
project_init_template.tcl
andproject_deinit_template.tcl
templates into the repo_dir, renaming them toproject_init.tcl
andproject_deinit.tcl
. - Edit them to enable sourcing
utility.tcl
andrepo_files.tcl
, and uncomment thesave_all
andcheck_all
function calls. - Copy and rename the
top_gitignore
from gitignores into the repo_dir as.gitignore
. If you use IPs or BDs, you can create subdirectories for them and add their gitignores (ip_gitignore
andbd_gitignore
as well). - Copy and rename the
project_create_template.tcl
file into the repo_dir (conventionally named as<repository name>.tcl
) and edit it to change the repository name and the part number. - Close and reopen the project. You are now ready to use the project. Remember when creating files/IPs/BDs that they do not go in the default location, but anywhere else in the repo_dir other than vivado_project.