pwm-controller/tcl/package_ip.tcl

152 lines
4.0 KiB
Tcl

# Parse the interface configuration and create a new interface
# in the current core
#
# @param iface_name Name of the interface to crate
# @param iface_conf Dictionary containing the interface configuration, parsed
# from hog.tcl ReadConf
#
proc ParseInterfaceConf { iface_name iface_conf } {
puts "Parsing interface $iface_name"
set iface_protocol [dict get $iface_conf "INTERFACE"]
variable infer false
if { [dict exists $iface_conf "INFER"] } {
set infer [dict get $iface_conf "INFER"]
}
if { $infer } {
puts "Inferring interface"
set ports [split [dict get $iface_conf "PORTS"]]
puts "Using ports: $ports"
set result [ipx::infer_bus_interface $ports $iface_protocol [ipx::current_core]]
# Inferred name could differ from the desired name, so set it
set inferred_name [lindex $result 2]
set created_iface [ipx::get_bus_interfaces $inferred_name -of_objects [ipx::current_core]]
set_property NAME $iface_name $created_iface
} else {
puts "Manually creating interface"
}
}
set gitroot [exec git rev-parse --show-toplevel]
set hogroot "$gitroot/Hog"
puts "Hog root: $hogroot"
puts "Sourcing hog.tcl"
# Using ReadConf
source -notrace "$hogroot/Tcl/hog.tcl"
if { $argc < 1 } {
puts "Usage: vivado -mode batch -source package_ip.tcl -tclargs PROJECT_NAME"
exit -1
}
set proj_name [lindex $argv 0]
set tmp_proj_name "tmp_$proj_name"
puts "Packaging $proj_name"
set proj_top_dir "$gitroot/Top/$proj_name"
set proj_dir "$gitroot/Projects/$proj_name"
set proj_file "$proj_dir/$proj_name.xpr"
set ip_conf_file "$proj_top_dir/ip.conf"
puts "Reading configuration file $ip_conf_file"
set ip_conf [ReadConf "$ip_conf_file"]
puts "IP Configuration: $ip_conf"
if { [dict exists $ip_conf main] == 0 } {
puts "No main section in IP configuration!"
exit -2
}
set ip_root "$gitroot/[dict get $ip_conf main ROOT]"
set ip_vendor [dict get $ip_conf main VENDOR]
set ip_library [dict get $ip_conf main LIBRARY]
set ip_taxonomy [dict get $ip_conf main TAXONOMY]
puts "Opening project $proj_file"
open_project "$proj_file"
puts "Packaging project"
ipx::package_project -root_dir "$ip_root" -vendor "$ip_vendor" -library "$ip_library" -taxonomy "$ip_taxonomy" -import_files -set_current false
set ip_component_file "$ip_root/component.xml"
puts "Unloading core"
ipx::unload_core "$ip_component_file"
ipx::edit_ip_in_project -name "$tmp_proj_name" -upgrade true -directory "$ip_root" "$ip_component_file"
update_compile_order -fileset sources_1
current_project "$tmp_proj_name"
# Remove inferred interfaces and memory maps. Start from a blank slate.
puts "Removing inferred interfaces"
foreach iface [ipx::get_bus_interfaces -of_objects [ipx::current_core]] {
set iface_name [lindex $iface 2]
puts "Removing inferred bus interface $iface_name"
ipx::remove_bus_interface $iface_name [ipx::current_core]
}
foreach memmap [ipx::get_memory_maps -of_objects [ipx::current_core]] {
set memmap_name [lindex $memmap 2]
puts "Removing inferred memory map $memmap_name"
ipx::remove_memory_map $memmap_name [ipx::current_core]
}
foreach param [ipx::get_user_parameters -of_objects [ipx::current_core]] {
set param_name [lindex $param 2]
if { $param_name == "Component_Name" } {
continue
}
puts "Removing inferred user parameter $param_name"
ipx::remove_user_parameter $param_name [ipx::current_core]
}
puts "Parsing interfaces"
foreach {key val} $ip_conf {
if { [string first "interface" "$key"] == 0 } {
set sepidx [string first "." "$key"]
set iface_name [string range "$key" [expr $sepidx + 1] [string length "$key"]]
ParseInterfaceConf "$iface_name" $val
} else {
puts "$key is not an interface"
}
}
puts "Packaging IP"
# Increment revision
set rev [get_property core_revision [ipx::current_core]]
incr rev
set_property core_revision $rev [ipx::current_core]
ipx::update_source_project_archive -component [ipx::current_core]
ipx::create_xgui_files [ipx::current_core]
ipx::update_checksums [ipx::current_core]
ipx::check_integrity [ipx::current_core]
ipx::save_core [ipx::current_core]
close_project
puts "Done"