Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
16598 Discussions

Command line equivalent of Qsys->Export System as hw.tcl Component

Altera_Forum
Honored Contributor II
3,125 Views

I am trying to figure out how to convert a Qsys file into a hw.tcl file. You can do it from the GUI by File->Export System as hw.tcl Component, but when you do that there is no record of the command line tool that is run. With other GUI actions you can usually see the command line invocation as part of the log. 

 

Does anyone know how to do this from the command line? 

 

Bonus points: 

 

I am trying to make a hw.tcl file for an existing Qsys system because I want to have additional module properties set when the subsystem is used in the top-level Qsys system. Do you know of a way to add these properties to the low-level Qsys system such that when the hw.tcl file for it is generated it will contain my desired set_module_property commands? 

 

Thanks, 

 

-Pete
0 Kudos
10 Replies
Altera_Forum
Honored Contributor II
1,441 Views

 

--- Quote Start ---  

 

Does anyone know how to do this from the command line? 

 

--- Quote End ---  

 

Yes I do :)
0 Kudos
Altera_Forum
Honored Contributor II
1,441 Views

Ok, I suppose I can provide a little more detail and even an example ... 

 

http://www.alteraforum.com/forum/showthread.php?t=45927 

 

The "Magic" command you are looking for is discussed here 

 

http://www.alterawiki.com/wiki/qsys_scripts 

 

Read the synthesis scripts I created for the DE0-nano project and you'll see how I used this script to automate the build. 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,441 Views

Dave, 

 

Thanks for the expanded answer. However I get an error saying that save_script.tcl does not exist when I run the command. I created my own script that uses the export_hw_tcl command to write the hw.tcl file though. I can attach that here. I would like the script to write the hw.tcl file to the current directory rather than the directory where it read the qsys file from. My script copies the qsys file to the current directory and then loads it. When I run export_hw_tcl though I get an info message saying "No save path defined. Defaulting to working directory." Do you know how I can set the save path and thus avoid copying the file and then removing the copy at the end? And if so, please tell me. 

 

Here is my script: 

 

package require -exact qsys 14.0 

 

 

file copy -force $system . 

load_system [ file tail $system ] 

set system_name [ file tail [ file root $system ] ] 

export_hw_tcl 

file delete -force [ file tail $system ] ] 

 

I use a --cmd argument to set the $system variable to point to my qsys file. It doesn't look like qsys-script supports the same command line processing functions as quarts_sh.  

 

Thanks, 

 

-Pete
0 Kudos
Altera_Forum
Honored Contributor II
1,441 Views

Hi Pete, 

 

--- Quote Start ---  

 

Thanks for the expanded answer. However I get an error saying that save_script.tcl does not exist when I run the command. 

 

--- Quote End ---  

 

That is the script you download from the Wiki page I linked to. 

 

 

--- Quote Start ---  

 

I created my own script that uses the export_hw_tcl command to write the hw.tcl file though. 

 

--- Quote End ---  

 

So that I can help you, I'd like to compare the method you are using (Qsys Export to _hw.tcl) versus the Wiki script ... which version of Quartus are you using? 

 

In the meantime, synthesize the DE0-nano SDRAM design and look at the qsys_system.tcl script. Once you have built that design, use the Qsys export as hw.tcl option and see if its the same (or at least similar). 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,441 Views

Dave, 

 

I am using Quartus 14.0. Sorry for being clueless about downloading the script from the wiki. 

 

Your script produces similar results to the export_hw_tcl command. The main differences I can see so far are that the export_hw_tcl result does not have the save_system command at the end. Which I think makes sense as the desired goal is to produce a hw.tcl file which can create the system inside qsys. A further difference is that the export_hw_tcl result has everything except the module properties wrapped in a compose procedure. The export_hw_tcl result also has some set_interconnect_requirements at the end that your script is missing as well. 

 

Is your script somehow related to the export_hw_tcl command? The comments are matching so either you are emulating the Altera script, or vice versa, or the scripts have some common pedigree. I am going to make a stab at modifying your script to produce results which are more similar to what I am seeing with export_hw_tcl in 14.0. That way I can be more confident that it produces what I need but also gives me better control over the result. I wanted to be able to set some module properties as well, so having a script will give me more control over that as well. I'll keep you posted. 

 

Thanks, 

 

-Pete
0 Kudos
Altera_Forum
Honored Contributor II
1,441 Views

 

--- Quote Start ---  

 

Is your script somehow related to the export_hw_tcl command? The comments are matching so either you are emulating the Altera script, or vice versa, or the scripts have some common pedigree.  

 

--- Quote End ---  

 

 

To some degree, that is what we are trying to establish. If you read the comments in the Tcl scripts in the example scripts/ folder, it tells you how I created the scripts. Basically I created Qsys .qsys XML files under several versions of Quartus, then used the Wiki script to convert them to Tcl so that I had a method of creating a .qsys file from a Tcl script in a Quartus-version-independent manner. 

 

The Qsys Export to hw.tcl procedure is used to create a Qsys *component*, so the resulting hw.tcl files should be similar, but not the same, since my objective was to create the top-level Qsys system, not a component that you include in a Qsys system ... though after I take a look at exporting, it might be easy enough to support that option too. 

 

 

--- Quote Start ---  

 

I am going to make a stab at modifying your script to produce results which are more similar to what I am seeing with export_hw_tcl in 14.0. That way I can be more confident that it produces what I need but also gives me better control over the result. I wanted to be able to set some module properties as well, so having a script will give me more control over that as well. I'll keep you posted. 

 

--- Quote End ---  

 

Cool! Keep hacking away on it. Its not too hard to add callbacks for elaboration, generation, etc. If you haven't figured those out, I can post some example hw.tcl files. 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,441 Views

Dave, 

 

So I modified your script to more closely match the one generated by export_hw_tcl in Quartus 14.0. I am new to Quartus, new to Tcl, and have only tested it on one system so there are likely a number of issues. I did find a bug with your script though where you print the exported interfaces. Your regexp for finding the type should be {_[^_]*$} instead of {_[^_]*}. I agree it would be nice to have an API for that rather than being forced to guess based on the naming. Next I am going to add hooks so I can set some module parameters from the command line which is the whole reason for going down this rabbit hole in the first place. 

 

I don't know how to attach a file to this thread so I will just include the script inline below. 

 

Thanks, 

 

-Pete 

 

#  

# This script saves the current system as a qsys hw.tcl file. The 

# intent is to emulate the export_hw_tcl command but give greater 

# control over the results. The resulting file should be able to be 

# imported into Qsys. 

#  

# This script is based heavily on the script Save_script.tcl written 

# by David Hawkins and found at 

# http://www.alterawiki.com/wiki/qsys_scripts 

#  

# Usage: qsys-script --script=export_hw_tcl.tcl --system-file=my_system.qsys 

#  

# The script writes: 

# * module properties 

# * instances in the system, with parameters 

# * connections in the system, with parameters 

# * exported interfaces 

# * interconnect requirements 

#  

# Known limitations: 

# * Disabled modules are culled. 

#  

# * No diagnostics if the system contains instances of unknown components. 

#  

# * there's no API to get the real system name for a system loaded from 

# a .qsys file ("$${FILENAME}" ain't it!). 

#  

# * I haven't tested any fancy quoting for parameters with tcl special 

# characters in them. 

#  

# * There is no api to query an interface type and direction. 

# We're extracting it from the interface "CLASS_NAME". It works for 

# now, but would be cleaner if we had direct API for these queries. 

#  

# * There is no API to manage: 

# * UI sort-order 

# * Custom (SOPC-compatible) exported signal names 

 

package require -exact qsys 14.0 

 

# procedure to quote stuff. If we need to make the escaping better, 

# this is the place to do it. 

proc quote { stuff } { 

return "{$stuff}" 

 

# determine the system name 

if {[expr ! [info exists system_name]]} { 

set system_name [ get_module_property NAME ] 

if { [string equal $system_name "\$\${FILENAME}" ]} { 

set system_name "new_system" 

 

# determine th eoutput file name 

if {[expr ! [info exists hw_tcl_file]]} { 

set hw_tcl_file "${system_name}_hw.tcl" 

set script_file [ open "$hw_tcl_file" w ] 

 

# write the API version this script is writing 

puts $script_file "package require -exact qsys 14.0" 

 

send_message Info "Writing system script to $hw_tcl_file" 

 

# write all the top-level system properties 

send_message Info "Writing module properties" 

puts $script_file "# module properties ('module' here means 'system' or 'top level module')" 

set properties [ get_module_properties ] 

foreach property $properties { 

set value [ quote [ get_module_property $property ] ] 

puts $script_file "set_module_property $property $value" 

puts $script_file "" 

 

puts $script_file "# default module properties" 

array set default_module_properties  

[ list  

{AUTHOR} {author}  

{DESCRIPTION} {default description}  

{GROUP} {default group}  

{VERSION} {1.0}  

 

foreach module_property [array names default_module_properties] { 

set property_value [ quote $default_module_properties($module_property) ] 

puts $script_file "set_module_property $module_property $property_value" 

puts $script_file "" 

 

puts $script_file "set_module_property COMPOSITION_CALLBACK compose" 

puts $script_file "set_module_property opaque_address_map false" 

puts $script_file "" 

 

puts $script_file "proc compose { } {" 

 

# write instances and instance parameters 

send_message Info "Writing instances" 

puts $script_file " # Instances and instance parameters" 

puts $script_file " # (disabled instances are intentionally culled)" 

set instances [ get_instances ] 

foreach instance $instances { 

set enabled [ get_instance_property $instance ENABLED ] 

if { [string equal -nocase "$enabled" true]} { 

set type [ get_instance_property $instance CLASS_NAME ] 

set version [ get_instance_property $instance VERSION ] 

puts $script_file " add_instance $instance $type $version" 

 

set parameters [ get_instance_parameters $instance ] 

foreach parameter $parameters { 

set parameter_value [ quote [ get_instance_parameter_value $instance $parameter ] ] 

puts $script_file " set_instance_parameter_value $instance [ quote $parameter ] $parameter_value" 

 

puts $script_file "" 

 

# write connections and connection parameters 

send_message Info "Writing connections" 

puts $script_file " # connections and connection parameters" 

set connections [ get_connections ] 

foreach connection $connections { 

set type [ get_connection_property $connection TYPE ] 

set start [ get_connection_property $connection START ] 

set end [ get_connection_property $connection END ] 

puts $script_file " add_connection $start $end $type" 

set parameters [ get_connection_parameters $connection ] 

foreach parameter $parameters { 

set value [ quote [ get_connection_parameter_value $connection $parameter ] ] 

puts $script_file " set_connection_parameter_value $connection $parameter $value" 

 

puts $script_file "" 

 

# write top-level interface exports 

send_message Info "Writing exports" 

puts $script_file " # exported interfaces" 

foreach export_interface [ get_interfaces ] { 

set inner_interface [ get_interface_property $export_interface EXPORT_OF ] 

regsub {\.[^.]*} $inner_interface "" instance 

regsub {^.*\.} $inner_interface "" instance_interface 

set classname [ get_instance_interface_property $instance $instance_interface CLASS_NAME ] 

regsub {_[^_]*$} $classname "" type 

regsub {^.*_} $classname "" direction 

puts $script_file " add_interface $export_interface $type $direction" 

puts $script_file " set_interface_property $export_interface EXPORT_OF $inner_interface" 

puts $script_file "" 

 

send_message Info "Writing interconnect requirements" 

puts $script_file " # interconnect requirements" 

set requirement_list [ get_interconnect_requirements ] 

foreach { element_id name value } $requirement_list { 

puts $script_file " set_interconnect_requirement [ quote $element_id ] [ quote $name ] [ quote $value ]" 

 

puts $script_file "}" 

 

close $script_file 

 

send_message Info "Saved $hw_tcl_file"
0 Kudos
Altera_Forum
Honored Contributor II
1,441 Views

Dave, 

 

OK, now I figured out attachments. It should be there now, although I needed to add a .txt extension. 

 

Thanks, 

 

-Pete
0 Kudos
Altera_Forum
Honored Contributor II
1,441 Views

Hey Pete, 

# This script is based heavily on the script Save_script.tcl written # by David Hawkins and found at # http://www.alterawiki.com/wiki/Qsys_scripts  

Sorry, I can't claim responsibility for the Wiki script, I just used it :) (The Wiki page probably has the author details) 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,441 Views

Dave, 

 

OK, I'll change the attribution then. Thanks for your help. 

 

-Pete
0 Kudos
Reply