on
Zynq 7000: Using a Command Line Workflow
So far we have used the graphical workflow to create block designs inside Xilinx Vivado. In this post I will present a different workflow based on TCL scripts, which can be run from the command line. Using TCL scripts a number of advantages when it comes it sharing designs across computers, with collaborators and when storing them in VCS (such as git). It also makes it easier to re-use (parts of) block designs in different projects.
This is part 3 of the Zynq 7000 seminar. If you have not used Vivado or the Zynq 7000 SoC before, I would recommend looking at the other posts in the series first:
- Getting started with the Xilinx Zynq 7000
- Using the ARM cores on the Xilinx Zynq 7000
- Zynq 7000: Using a Command Line Workflow [This Post]
- Zynq 7000: Adding Custom Blocks
The graphical interface is not the only method for programming the Zynq (or other Xilinx devices); instead a command-line based workflow can be used. In this post I will show how TCL scripts can be used to replicate the entire process we went through in the previous two posts, from creating the project through creating the block design to generating the bitstream. This example will still use block designs and projects; in future posts I will show examples that do not use block designs, or even projects.
There are a few benefits to using TCL scripts to generate the project and block designs. Xilinx project and block design files can be difficult to share between team members or devices; using a TCL script allows every user to create a new project locally, which is initialized to a known state. The TCL scripts are also much easier to place into version control systems such as Git, as they are just plain text files. Finally, when blocks designs are created by TCL scripts it becomes easier to re-use part of the design in a new project.
By using project mode and block designs in our TCL script we can still use all the good features of block designs, with the added benefits of better version control and easier re-use. If for any reason you want to inspect the generated project visually, you can simply open it in Vivado, and it will contain the same design as the project we created in the previous section.
LED Blinker
The first project we will consider is the LED blinking project, which was discussed in the first post in this series. The scripts to create this project can be found in this GitHub repository. The first script is the mk_proj.tcl script, which creates the project on disk, the second script is the src/bd/blinky.tcl file and the final script is the build.tcl script. The contents of the mk_proj.tcl script are shown below.
|
|
Lines 1-3 configure the parameters of the script: the name of the project, the part which we are targeting and the path of the directory where the project will be stored. Lines 5-12 deal with creating, or emptying, the project folder. Line 14 creates the project, using the parameters we configured at the top of the script. Line 16 calls another script to generate the block design; the contents of that script will be discussed next. Lines 18 and 19 are used to generate the HDL wrapper and add it to the project; and finally, line 21 reads the constraints file for this project.
On line 16 above we call the script src/bd/blinky.tcl which creates the block design. The contents of that script are shown in the code block below, and it follows closely the steps from before.
|
|
Lines 1 and 2 create a block design with the name that has been configured, and in lines 4-7 a new IP module is added, specifically the “Zynq7 Processing System” IP block, and a reference to this module is stored in the variable $processing_system. Lines 8-12 apply a block design automation rule to add the external interfaces FIXED_IO and DDR, which is the same automation step we used in the graphical workflow. Lines 14-17 configure the properties of the processing system, in this case it sets the frequency of FCLK0 (again, this only informs Vivado of the frequency, it does not modify or control it) and disables the AXI GP0 bus. Lines 19-21 create a second IP block, this time a “Binary Counter” block, and store a reference to it; lines 23-25 add the slice block to the design. Line 27 configures the width of the binary counter, and lines 29-34 configure the slice block, selecting the most significant bit from the counter output. Line 36 creates the output port connecting to the LED and lines 38-40 connect the clock signal to the counter; the counter output to the slice block and the output of the slice block to the output port for the LED. Finally, lines 4 optimizes the block diagram layout (this is not necessary, but helps when you inspect the design in the GUI), and line 43 saves the new block design to the disk; line 45 sets a variable with the path of the block design; this variable can subsequently be used in the mk_proj.tcl script.
The final script in this project is the build.tcl script. This script can be used after the project has been created to start the process of synthesis, implementation and bitstream generation. This script can also be run after any of the project’s RTL sources or constraints have been modified, to regenerate the bitstream. The contents of this script are listed below.
In the script above, lines 1 and 2 configure the project details, which have to match the mk_proj.tcl script. Line 4 opens the previously created project, and line 6 resets any existing synthesis results. Line 9 starts the synthesis of the project, and line 10 tells the script to block until synthesis is complete. Line 12 launches the implementation, including the bitstream generation, and line 13 blocks until the bitstream has been generated. Finally line 14 writes a message to the console to inform the user that the process has finished.
Based on my own experience I would believe that it is worth spending some time learning how to use a scripted workflow for Vivado. Being able to easily store the project files in Git for version control and team-wide collaboration has proven to be a great time-saver. Another reason why I like the scripts is that Vivado sometimes crashes and corrupts the block designs; in those situations, re-creating the block design is often the quickest solution and this is really easy to do with TCL scripts. The final reason I will mention is that the TCL scripts are much easier to re-use: with the TCL scripts you can easily copy-paste the sections of the design which you want to re-use in a different project.
Vivado has a nice feature to aid in learning the TCL commands: every action you take in the GUI runs a TCL command in the background, and these are shown in the console at the bottom of the screen. If you are not sure what command to use, you can open the GUI and perform the action there, then copy the command into your own TCL script. This really helped me get up to speed with the available commands when I first got started with the scripted workflow. You can also export a block design as a TCL script from the Vivado GUI and use that to learn the relevant commands. This option can be found under File > Export > Export Block Design. The exported scripts can be a bit difficult to follow, but nevertheles they can form a good starting point for your own TCL scripts, if necessary.
To use the scripted workflow, first clone the GitHub repository. Open a terminal in the git repository and source the Vivado settings script; you may have to chance the installation path (/opt/Xilinx) and version (2021.1) to the correct path for your setup.
I am using a Linux-based PC for these tutorials and so the commands are based on this setup, but it might be possible to recreate these steps on Windows as well. Next, change directory to the axi-gpio project and create a new directory to hold the Vivado output and temporary files:
Inside the new directory run the mk_proj.tcl script:
This script should take a few seconds to create and configure the blink-led project. After the script has finished, you could choose to open the project file, which is in the blink-led subdirectory, in the Vivado GUI. Or you could immediately continue to build the project and generate the bitstream:
|
|
This script will run the synthesis and implementation, so it will take longer to finish. As a reference, on my laptop it takes around four minutes to complete. When complete Vivado should exit without any errors and you should see “Implementation done!” in its output.
Now the bitstream is available to be loaded onto the Red Pitaya in exactly the same way as before. When the bitstream is programmed into the PL the LED should blink in the same way as in the first post.
LED Control
The second project we will consider is that developed in the second post in this series, which allows control over the LEDs from the ARM cores. The scripts to create this project can be found in this GitHub repository. The first script is the mk_proj.tcl script, which creates the project on disk, the second script is the src/bd/axi_gpio.tcl file and the final script is the build.tcl script. The contents of the mk_proj.tcl script are shown below.
|
|
The mk_proj.tcl file in this project is almost identical to the that in the blink-led project above. The only differences are in the name of the project and the name of the TCL script which generates the block design. The contents of that script, axi_gpio.tcl, are shown below.
|
|
This script is different from the previous project, because the block design contains different IP blocks. Lines 1-13 are the same as in the previous script, and lines 14-16 are very similar. However, the first difference with the previous block design is that the AXI_GP0 is not disabled in this project, as we will use it to communicate with the AXI GPIO block. Line 18 creates a second IP block, the AXI GPIO block, and stores a reference to it; line 19 configures the properties of the block, using the same values as in the graphical workflow. Lines 21-29 apply the second automation rule, which is the AXI4 rule which sets up the AXI4 network; lines 32-35 apply another automation rule to add the external GPIO port; line 36 configures the name of the newly created interface port. Lines 38 and 39 configure the address range for the AXI GPIO core, using the same parameters used previously in the graphical address editor Finally, line 41 saves the new block design to the disk and line 43 sets a variable with the path of the block design. This variable can subsequently be used in the mk_proj.tcl script.
The commands to configure and then build the project are almost identical to before:
At this point the bitstream will be available in the same location as in the previous post and it can be loaded on the Red Pitaya; the same C code from the previous post can be used to control the LEDs.
Summary
In this post we have seen how TCL scripts can be used to drive Vivado from the command line, as an alternative to using the GUI. There are a few advantages to using the command line workflow:
- The TCL scripts contain everything needed to regenerate the project. This makes it easy to do a clean build if Vivado crashes and corrupts the project, or incorrectly attempts to re-use cached results.
- The scripts are well suited to use with version control systems such as git, which allows you to easily track changes, compare revisions, archive your project pr share your project with other developers.
- Using a scripted workflow makes it easier to share and re-use parts of your design across projects and teams.
In this post the workflow still used Xilinx' project mode and block designs. This way developers can access the GUI at any point to inspect project settings or to visualize the design. There are, however, reasons why a developer may prefer to not use block designs, or even projects, and we will explore these options in future posts.