# # Cypress Semiconductor KitProg3 # # KitProg3 is CMSIS-DAP compliant adapter. However, it supports additional functionality # such as SPI/I2C bridging, Hardware acquire procedure for PSoC 4/5/6 devices, power control. # This functionality has been moved to separate driver to avoid pollution of generic CMSIS-DAP # with probe-specific code. # # Interface driver inherits all functionality of CMSIS-DAP including all tcl commands. # Additional functionality can be accessed via tcl using 'kitprog3' prefix # adapter driver kitprog3 proc get_kp3_version {kp3_fw_dir} { set result "" set ver_file "" catch { set ver_file [find "${kp3_fw_dir}/kitprog3.version"] } if { $ver_file != "" } { set fd [open $ver_file "r"] set ver [read -nonewline $fd] close $fd regsub -all {\s} $ver "" ver regsub -all {} $ver "" ver set result $ver } return $result } # # Get the MTB tool path by the given MTBQuery tool ID. # This function invokes the mtbquery executable passing the tool ID as an argument, # then extracts the tool's 'path' entry from its output and returns it. # See for details PROGTOOLS-3023 - 'OpenOCD : Integration with MTB Query API' # proc get_tool_dir {tools_dir tool_id} { set tool_dir "" set query_args "--toolinfo $tool_id" set status [catch {exec $tools_dir/mtbquery/mtbquery {*}$query_args} query_out] if { $status == 0 } { regexp {path\s:\s(.*)$} $query_out -> tool_dir } return $tool_dir } proc get_last_tooldir_ver {tool_list} { set filt_list "" set last_version "" # Check pattern 'tools_x..z.y' for {set i 0} {$i < [llength $tool_list]} {incr i} { set match "" set folder [lindex $tool_list $i] regexp {tools_[0-9]+\.[0-9]} $folder match if {$match != ""} { lappend filt_list $match } } # Get last version for {set i 0} {$i < [llength $filt_list]} {incr i} { set folder [lindex $filt_list $i] set version [string range $folder [string length "tools_"] end] lset filt_list $i $version if {$i == 0} { set last_version $version } elseif {$version > $last_version} { set last_version $version } } return "tools_$last_version" } set script_dir [file dirname [file join [pwd] [info script]]] set script_dir_list [file split $script_dir] if {[llength $script_dir_list] > 5} { if { [lsearch -exact $script_dir_list "packs"] != -1 && [lsearch -exact $script_dir_list "ModusToolbox"] != -1} { # Early Access Packs usage case while {[llength $script_dir_list] > 0} { set dir [lindex $script_dir_list end] if {$dir != "ModusToolbox"} { # Go backward until directory "ModusToolbox" reached # to ensure that algorithm passes by packs "tools" folder # that does not contain mtb-query set script_dir_list [lreplace $script_dir_list end end] } else { break } } set mtb_path [file join {*}[lrange $script_dir_list 0 end]] set path_list [file split $mtb_path] if { [catch {glob -directory $mtb_path tools_*} tools_list]} { set tools_dir "" } elseif {[llength $tools_list] == 1} { set tools_dir [lindex $tools_list 0] } else { set last_tooldir_ver [get_last_tooldir_ver [split $tools_list " "]] # Append ModusToolbox path with last tools directory lappend path_list $last_tooldir_ver set tools_dir [file join {*}[lrange $path_list 0 end]] } } else { # Modus Toolbox for {set dir_depth 1} {$dir_depth <= 5} {incr dir_depth} { set tools_dir [file join {*}[lrange [file split $script_dir] 0 end-$dir_depth]] set check_tool [lindex [file split $tools_dir] end] if { [string last "tools" $check_tool] != -1 } { break } } } # Get the latest fw-loader and KP firmware assets in the MTB 3.x environment (tools_3.x/ folder) set fw_loader_dir [get_tool_dir $tools_dir "1901ec91-2683-4ab4-8034-211b772c9a2b"] set kp3_fw_dir [get_tool_dir $tools_dir "2bd09d79-2620-45fd-9452-77d1dbfe41d5"] # If not found using mtbquery, try to find the assets in known folders at the same level as openocd if { $fw_loader_dir == ""} { set temp_path [file join $tools_dir "fw-loader"] if {[file exists $temp_path]} { set fw_loader_dir $temp_path } } if { $kp3_fw_dir == ""} { set temp_path [file join $tools_dir "kp-firmware"] if {[file exists $temp_path]} { set kp3_fw_dir $temp_path } } set kp3_fw_ver [get_kp3_version $kp3_fw_dir] if { $kp3_fw_dir != "" && $kp3_fw_ver != "" } { kitprog3 set_latest_version $kp3_fw_dir $kp3_fw_ver } }