cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Newbie
Newbie
12,595 Views
Registered: ‎03-13-2014

Vivado TCL set generics based on date / git hash

Hi all,

 

I'm posting this because I spent a lot of time looking for an example of setting multiple top-level generics in a pre-Synthesis tcl script in Vivado, passing date/time & git info, and I figure this will come in handy to a number of people who are looking to solve a similar problem (and probably me when I go Google searching for this again).

 

My top level has two 32-bit generics: DATE_CODE & HASH_CODE.

 

The pre-synthesis tcl script I run is:

 


# Current date, time, and seconds since epoch
# 0 = 4-digit year
# 1 = 2-digit year
# 2 = 2-digit month
# 3 = 2-digit day
# 4 = 2-digit hour
# 5 = 2-digit minute
# 6 = 2-digit second
# 7 = Epoch (seconds since 1970-01-01_00:00:00)
# Array index                                            0  1  2  3  4  5  6  7
set datetime_arr [clock format [clock seconds] -format {%Y %y %m %d %H %M %S %s}]
 
# Get the datecode in the yy-mm-dd-HH format
set datecode [lindex $datetime_arr 1][lindex $datetime_arr 2][lindex $datetime_arr 3][lindex $datetime_arr 4]
# Show this in the log
puts DATECODE=$datecode
 
# Get the git hashtag for this project
set curr_dir [pwd]
set proj_dir [get_property DIRECTORY [current_project]]
cd $proj_dir
set git_hash [exec git log -1 --pretty='%h']
# Show this in the log
puts HASHCODE=$git_hash
 
# Set the generics
set_property generic "DATE_CODE=32'h$datecode HASH_CODE=32'h$git_hash" [current_fileset]

 

References:

http://stackoverflow.com/questions/18141851/compile-date-and-time-in-fpga

http://www.tcl.tk/man/tcl/TclCmd/exec.htm

http://stackoverflow.com/questions/949314/how-to-retrieve-the-hash-for-the-current-commit-in-git

3 Replies
Highlighted
Xilinx Employee
Xilinx Employee
12,592 Views
Registered: ‎03-24-2008

very cool!

Greg Daughtry
Vivado Product Marketing Director, Xilinx, Inc.
0 Kudos
Highlighted
Contributor
Contributor
6,679 Views
Registered: ‎07-04-2016

Hi, awesome - very usable code.

 

i have this idea

maybe, you create another variable, that holds the value.

and that value is a string containing a path to a file.

and that file stores all the diffs of all the files (diff with previous commit)

 

maybe you can do that?

0 Kudos
Highlighted
Participant
Participant
931 Views
Registered: ‎04-07-2017

Thanks a lot for this script.

I suggest a small improvement, to make it more tolerant for existing designs: Right now it would overwrite all previously set generics (e.g. in through the GUI). The following version takes care of that:

# Current date, time, and seconds since epoch
# 0 = 4-digit year
# 1 = 2-digit year
# 2 = 2-digit month
# 3 = 2-digit day
# 4 = 2-digit hour
# 5 = 2-digit minute
# 6 = 2-digit second
# 7 = Epoch (seconds since 1970-01-01_00:00:00)
# Array index                                            0  1  2  3  4  5  6  7
set datetime_arr [clock format [clock seconds] -format {%Y %y %m %d %H %M %S %s}]
 
# Get the datecode in the yy-mm-dd-HH format
set datecode [lindex $datetime_arr 1][lindex $datetime_arr 2][lindex $datetime_arr 3][lindex $datetime_arr 4]
# Show this in the log
puts DATECODE=$datecode
 
# Get the git hashtag for this project
set curr_dir [pwd]
set proj_dir [get_property DIRECTORY [current_project]]
cd $proj_dir
set git_hash [exec git log -1 --pretty='%h']
# Show this in the log
puts HASHCODE=$git_hash
 
# Update the generics
set initial_generics [get_property generic [current_fileset]]
set_property generic "$initial_generics DATE_CODE=32'h$datecode HASH_CODE=32'h$git_hash" [current_fileset]
0 Kudos