24 set tcl_path [
file normalize "[
file dirname [
info script]]/.."]
25 source $tcl_path/hog.tcl
29 if {[
info exists env(HOG_TCLLIB_PATH)]} {
30 lappend auto_path $env(HOG_TCLLIB_PATH)
32 puts "ERROR: To run Hog with Microsemi Libero SoC, you need to define the HOG_TCLLIB_PATH variable."
37 if {[
catch {
package require struct::matrix} ERROR]} {
38 puts "$ERROR\n If you are running this script on tclsh, you can fix this by installing 'tcllib'"
45 set project [
file tail $project_name]
46 set old_path [
file normalize "../../Projects/${project_name}/$project.runs/synth_1"]
52 if {[
info exists env(HOG_EXTERNAL_PATH)]} {
53 set ext_path $env(HOG_EXTERNAL_PATH)
54 Msg Info "Found environment variable HOG_EXTERNAL_PATH, setting path for external files to $ext_path..."
62 set proj_file "[get_property DIRECTORY [current_project]]/$project.prr"
64 set proj_file [get_property parent.project_path [current_project]]
66 set proj_dir [
file normalize [
file dirname $proj_file]]
67 set proj_name [
file rootname [
file tail $proj_file]]
70 set proj_name [
lindex $quartus(args) 1]
73 set proj_file [
file normalize "$proj_dir/$proj_name.qpf"]
75 set hogQsysFileName [
file normalize "$proj_dir/.hog/.hogQsys.md5"]
76 if {[
file exists $hogQsysFileName] != 0} {
77 set hogQsysFile [open $hogQsysFileName r]
78 set hogQsysFileLines [
split [read $hogQsysFile] "\n"]
79 foreach line $hogQsysFileLines {
80 set fileEntry [
split $line "\t"]
81 set fileEntryName [
lindex $fileEntry 0]
82 if {$fileEntryName != ""} {
83 if {[
file exists $fileEntryName]} {
84 set newMd5Sum [
Md5Sum $fileEntryName]
85 set oldMd5Sum [
lindex $fileEntry 1]
86 if {$newMd5Sum != $oldMd5Sum} {
87 Msg Warning "The checksum for file $fileEntryName is not equal to the one saved in $hogQsysFileName.\n\
88 New checksum $newMd5Sum, old checksum $oldMd5Sum. \
89 Please check the any changes in the file are correctly propagated to git!"
92 Msg Warning "File $fileEntryName not found... Will not check Md5Sum!"
98 set proj_dir [
file normalize [
file dirname "[project_data -dir]/../.."]]
99 set proj_name [
file tail $proj_dir]
100 set project $proj_name
102 set proj_dir [
file normalize "[
pwd]/.."]
103 set proj_name [
file tail $proj_dir]
104 set project $proj_name
107 set proj_file $old_path/[
file tail $old_path].xpr
108 set proj_dir [
file normalize [
file dirname $proj_file]]
109 set proj_name [
file rootname [
file tail $proj_file]]
110 Msg CriticalWarning "You seem to be running locally on tclsh, so this is a debug message. \
111 The project file will be set to $proj_file and was derived from the path you launched this script from: $old_path. \
112 If you want this script to work properly in debug mode, please launch it from the top folder of one project, \
113 for example Repo/Projects/fpga1/ or Repo/Top/fpga1/"
117 set repo_path [
file normalize "$tcl_path/../.."]
123 set flavour [
string map {. ""} [
file extension $proj_name]]
124 if {$flavour != ""} {
125 if {[
string is integer $flavour]} {
126 Msg Info "Project $proj_name has flavour = $flavour, the generic variable FLAVOUR will be set to $flavour"
128 Msg Warning "Project name has a unexpected non numeric extension, flavour will be set to -1"
139 lassign [
GetRepoVersions [
file normalize $repo_path/Top/$group/$proj_name] $repo_path $ext_path] \
140 commit version hog_hash hog_ver \
143 cons_ver cons_hash ext_names ext_hashes \
144 xml_hash xml_ver user_ip_repos user_ip_hashes user_ip_vers
147 set describe [
GetHogDescribe [
file normalize $repo_path/Top/$group/$proj_name] $repo_path]
148 set dst_dir [
file normalize "bin/$group/$proj_name\-$describe"]
149 Msg Info "Creating $dst_dir..."
150 file mkdir $dst_dir/reports
154 set confDict [dict create]
155 set allow_fail_on_check 0
156 set allow_fail_on_conf 0
157 set allow_fail_on_list 0
158 set allow_fail_on_git 0
160 if {[
file exists "$tcl_path/../../Top/$group/$proj_name/hog.conf"]} {
161 set confDict [
ReadConf "$tcl_path/../../Top/$group/$proj_name/hog.conf"]
162 set allow_fail_on_check [
DictGet [
DictGet $confDict "hog"] "ALLOW_FAIL_ON_CHECK" 0]
163 set allow_fail_on_conf [
DictGet [
DictGet $confDict "hog"] "ALLOW_FAIL_ON_CONF" 0]
164 set allow_fail_on_list [
DictGet [
DictGet $confDict "hog"] "ALLOW_FAIL_ON_LIST" 0]
165 set allow_fail_on_git [
DictGet [
DictGet $confDict "hog"] "ALLOW_FAIL_ON_GIT" 0]
166 set full_diff_log [
DictGet [
DictGet $confDict "hog"] "FULL_DIFF_LOG" 0]
173 Msg Info "Running list file checker..."
175 if {![
string equal ext_path ""]} {
176 set argv [list "-ext_path" "$ext_path" "-project" "$group/$proj_name" "-outDir" "$dst_dir" "-log" "[
expr {!$allow_fail_on_check}]"]
178 set argv [list "-project" "$group/$proj_name" "-outDir" "$dst_dir" "-log" "[
expr {!$allow_fail_on_check}]"]
180 source $tcl_path/utils/check_list_files.tcl
181 if {[
file exists "$dst_dir/diff_list_and_conf.txt"]} {
183 set list_mismatch [
expr {$SrcListErrorCnt + $ConListErrorCnt > 0}]
184 set conf_mismatch [
expr {$ConfErrorCnt > 0}]
185 if {($list_mismatch && !$allow_fail_on_list) || ($conf_mismatch && !$allow_fail_on_conf)} {
186 Msg CriticalWarning "Project list or hog.conf mismatch, will use current SHA ($this_commit) and version will be set to 0."
190 Msg Warning "Project list or hog.conf mismatch found, but ignored because ALLOW_FAIL_ON_LIST/ALLOW_FAIL_ON_CONF is set in hog.conf."
200 Msg Info "Evaluating non committed changes..."
201 set found_uncommitted 0
203 set diff_stat [
Git "diff --stat"]
205 set found_uncommitted 1
206 Msg Warning "Found non committed changes:..."
207 if {$full_diff_log} {
210 Msg Status "$diff_stat"
212 set fp [open "$dst_dir/diff_presynthesis.txt" w+]
215 Msg CriticalWarning "Repository is not clean, will use current SHA ($this_commit) and create a dirty bitfile..."
218 lassign [
GetHogFiles -ext_path "$ext_path" "$tcl_path/../../Top/$group/$proj_name/list/" "$tcl_path/../../"] listLibraries listProperties
220 if {!$allow_fail_on_git} {
221 foreach library [dict keys $listLibraries] {
222 set fileNames [dict get $listLibraries $library]
223 foreach fileName $fileNames {
225 set fp [open "$dst_dir/diff_presynthesis.txt" a+]
226 set found_uncommitted 1
227 puts $fp "\n[
Relative $tcl_path/../../ $fileName] is not in the git repository"
228 Msg CriticalWarning "[
Relative $tcl_path/../../ $fileName] is not in the git repository. \
229 Will use current SHA ($this_commit) and version will be set to 0."
235 if {$found_uncommitted == 0} {
236 Msg Info "No uncommitted changes found."
244 lassign [
GitRet "tag -l v0.0.1"] status result
246 Msg CriticalWarning "Repository does not have an initial v0.0.1 tag yet. Please create it with \"git tag v0.0.1\" "
250 Msg Info "Git describe for $commit is: $describe"
253 set commit $this_commit
255 Msg Info "Found last SHA for $proj_name: $commit"
256 if {$commit != $this_commit} {
257 set count [
Git "rev-list --count $commit..$this_commit"]
258 Msg Info "The commit in which project $proj_name was last modified is $commit, that is $count commits older than current commit $this_commit."
262 if {$xml_hash != ""} {
263 set xml_dst [
file normalize $old_path/../xml]
264 Msg Info "Creating XML directory $xml_dst..."
266 Msg Info "Copying xml files to $xml_dst and replacing placeholders with xml version $xml_ver..."
275 set maxThreads [
GetMaxThreads [
file normalize ./Top/$group/$proj_name/]]
277 if {$maxThreads != 1} {
278 Msg Warning "Multithreading enabled. Bitfile will not be deterministic. Number of threads: $maxThreads"
280 Msg Info "Disabling multithreading to assure deterministic bitfile"
285 set_param general.maxThreads $maxThreads
288 if {[
catch {
package require ::quartus::project} ERROR]} {
289 Msg Error "$ERROR\n Can not find package ::quartus::project"
295 project_open $proj_name -current_revision
297 set_global_assignment -name NUM_PARALLEL_PROCESSORS $maxThreads
300 set_option -max_parallel_jobs $maxThreads
303 set clock_seconds [
clock seconds]
304 set tt [
clock format $clock_seconds -format {%d/%m/%Y at %H:%M:%S}]
307 set date [
Git "log -1 --format=%cd --date=format:%d%m%Y $commit"]
308 set timee [
Git "log -1 --format=%cd --date=format:00%H%M%S $commit"]
310 Msg Warning "Found Git version older than 2.9.3. Using current date and time instead of commit time."
311 set date [
clock format $clock_seconds -format {%d%m%Y}]
312 set timee [
clock format $clock_seconds -format {00%H%M%S}]
318 set proj_group_and_name "$group/$proj_name"
321 prj_project open $proj_dir/$proj_name.ldf
323 WriteGenerics "synth" $repo_path $proj_group_and_name $date $timee $commit $version \
324 $top_hash $top_ver $hog_hash $hog_ver \
325 $cons_ver $cons_hash $libs $vers \
326 $hashes $ext_names $ext_hashes \
327 $user_ip_repos $user_ip_vers $user_ip_hashes \
328 $flavour $xml_ver $xml_hash
334 set status_file [
file normalize "$old_path/../versions.txt"]
337 if {[
catch {
package require ::quartus::project} ERROR]} {
338 Msg Error "$ERROR\n Can not find package ::quartus::project"
344 project_open $proj_name -current_revision
347 set zero_ttb 00000000
349 binary scan [
binary format H* [
string map {{'} {}} $date]] B32 bits
350 set_parameter -name GLOBAL_DATE $bits
351 binary scan [
binary format H* [
string map {{'} {}} $timee]] B32 bits
352 set_parameter -name GLOBAL_TIME $bits
353 binary scan [
binary format H* [
string map {{'} {}} $version]] B32 bits
354 set_parameter -name GLOBAL_VER $bits
355 binary scan [
binary format H* [
string map {{'} {}} $commit]] B32 bits
356 set_parameter -name GLOBAL_SHA $bits
357 binary scan [
binary format H* [
string map {{'} {}} $top_hash]] B32 bits
358 set_parameter -name TOP_SHA $bits
359 binary scan [
binary format H* [
string map {{'} {}} $top_ver]] B32 bits
360 set_parameter -name TOP_VER $bits
361 binary scan [
binary format H* [
string map {{'} {}} $hog_hash]] B32 bits
362 set_parameter -name HOG_SHA $bits
363 binary scan [
binary format H* [
string map {{'} {}} $hog_ver]] B32 bits
364 set_parameter -name HOG_VER $bits
365 binary scan [
binary format H* [
string map {{'} {}} $cons_ver]] B32 bits
366 set_parameter -name CON_VER $bits
367 binary scan [
binary format H* [
string map {{'} {}} $cons_hash]] B32 bits
368 set_parameter -name CON_SHA $bits
370 if {$use_ipbus == 1} {
371 binary scan [
binary format H* [
string map {{'} {}} $xml_ver]] B32 bits
372 set_parameter -name XML_VER $bits
373 binary scan [
binary format H* [
string map {{'} {}} $xml_hash]] B32 bits
374 set_parameter -name XML_SHA $bits
378 foreach l $libs v $vers h $hashes {
379 binary scan [
binary format H* [
string map {{'} {}} $v]] B32 bits
380 set_parameter -name "[
string toupper $l]_VER" $bits
381 binary scan [
binary format H* [
string map {{'} {}} $h]] B32 bits
382 set_parameter -name "[
string toupper $l]_SHA" $bits
385 foreach e $ext_names h $ext_hashes {
386 binary scan [
binary format H* [
string map {{'} {}} $h]] B32 bits
387 set_parameter -name "[
string toupper $e]_SHA" $bits
390 if {$flavour != -1} {
391 set_parameter -name FLAVOUR $flavour
394 if {![
file exists "$old_path/output_files"]} {
395 file mkdir "$old_path/output_files"
398 set status_file "$old_path/output_files/versions.txt"
402 puts "Hog:DEBUG GLOBAL_DATE=$date GLOBAL_TIME=$timee"
403 puts "Hog:DEBUG GLOBAL_SHA=$commit TOP_SHA=$top_hash"
404 puts "Hog:DEBUG CON_VER=$cons_ver CON_SHA=$cons_hash"
405 puts "Hog:DEBUG XML_SHA=$xml_hash GLOBAL_VER=$version TOP_VER=$top_ver"
406 puts "Hog:DEBUG XML_VER=$xml_ver HOG_SHA=$hog_hash HOG_VER=$hog_ver"
407 puts "Hog:DEBUG LIBS: $libs $vers $hashes"
408 puts "Hog:DEBUG EXT: $ext_names $ext_hashes"
409 puts "Hog:DEBUG FLAVOUR: $flavour"
410 set status_file "$old_path/versions.txt"
412 Msg Info "Opening version file $status_file..."
413 set status_file [open $status_file "w+"]
415 Msg Status " ------------------------- PRE SYNTHESIS -------------------------"
417 Msg Status " Firmware date and time: $date, $timee"
418 if {$flavour != -1} {
419 Msg Status " Project flavour: $flavour"
424 puts $status_file "## $group/$proj_name Version Table\n"
426 puts $status_file "## $proj_name Version Table\n"
432 m add row "| \"**File set**\" | \"**Commit SHA**\" | **Version** |"
433 m add row "| --- | --- | --- |"
434 Msg Status " Global SHA: $commit, VER: $version"
435 m add row "| Global | $commit | $version |"
438 Msg Status " Constraints SHA: $cons_hash, VER: $cons_ver"
439 m add row "| Constraints | $cons_hash | $cons_ver |"
441 if {$use_ipbus == 1} {
443 Msg Status " IPbus XML SHA: $xml_hash, VER: $xml_ver"
444 m add row "| \"IPbus XML\" | $xml_hash | $xml_ver |"
447 Msg Status " Top SHA: $top_hash, VER: $top_ver"
448 m add row "| \"Top Directory\" | $top_hash | $top_ver |"
451 Msg Status " Hog SHA: $hog_hash, VER: $hog_ver"
452 m add row "| Hog | $hog_hash | $hog_ver |"
454 Msg Status " --- Libraries ---"
455 foreach l $libs v $vers h $hashes {
457 Msg Status " $l SHA: $h, VER: $v"
458 m add row "| \"**Lib:** $l\" | $h | $v |"
461 if {[
llength $user_ip_repos] > 0} {
462 Msg Status " --- User IP Repositories ---"
463 foreach r $user_ip_repos v $user_ip_vers h $user_ip_hashes {
465 set repo_name [
file tail $r]
466 Msg Status " $repo_name SHA: $h, VER: $v"
467 m add row "| \"**Repo:** $repo_name\" | $h | $v |"
471 if {[
llength $ext_names] > 0} {
472 Msg Status " --- External Libraries ---"
473 foreach e $ext_names eh $ext_hashes {
474 Msg Status " $e SHA: $eh"
475 m add row "| \"**Ext:** $e\" | $eh | \" \" |"
479 Msg Status " -----------------------------------------------------------------"
481 puts $status_file [m format 2string]
482 puts $status_file "\n\n"
489 set user_pre_synthesis_file "./Top/$group/$proj_name/pre-synthesis.tcl"
490 if {[
file exists $user_pre_synthesis_file]} {
491 Msg Info "Sourcing user pre-synthesis file $user_pre_synthesis_file"
492 source $user_pre_synthesis_file