bootloader.tcl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. global usbblaster_name
  2. global test_device
  3. global instance_index
  4. set instance_index 42
  5. proc write_data { val } {
  6. global instance_index
  7. open_port
  8. device_lock -timeout 10000
  9. device_virtual_ir_shift -instance_index $instance_index -ir_value 2 -no_captured_ir_value
  10. foreach {word} $val {
  11. set word [format %08s $word]
  12. device_virtual_dr_shift -dr_value $word -instance_index $instance_index -length 32 -no_captured_dr_value -value_in_hex
  13. }
  14. device_virtual_ir_shift -instance_index $instance_index -ir_value 0 -no_captured_ir_value
  15. close_port
  16. }
  17. proc read_data {} {
  18. global instance_index
  19. set val [format %032s 0]
  20. open_port
  21. device_lock -timeout 10000
  22. device_virtual_ir_shift -instance_index $instance_index -ir_value 3 -no_captured_ir_value
  23. set l [device_virtual_dr_shift -dr_value $val -instance_index $instance_index -length 32]
  24. device_virtual_ir_shift -instance_index $instance_index -ir_value 0 -no_captured_ir_value
  25. close_port
  26. puts $l
  27. }
  28. proc set_address { adr } {
  29. global instance_index
  30. set adr [format %03s $adr]
  31. open_port
  32. device_lock -timeout 10000
  33. device_virtual_ir_shift -instance_index $instance_index -ir_value 1 -no_captured_ir_value
  34. device_virtual_dr_shift -dr_value $adr -instance_index $instance_index -length 12 -no_captured_dr_value -value_in_hex
  35. device_virtual_ir_shift -instance_index $instance_index -ir_value 0 -no_captured_ir_value
  36. close_port
  37. }
  38. proc open_port {} {
  39. global usbblaster_name
  40. global test_device
  41. open_device -hardware_name $usbblaster_name -device_name $test_device
  42. }
  43. proc close_port {} {
  44. catch {device_unlock}
  45. catch {close_device}
  46. }
  47. proc download_file { base fname } {
  48. set fp [open $fname r]
  49. set data [read $fp]
  50. close $fp
  51. set_address $base
  52. write_data $data
  53. }
  54. proc connect_jtag {} {
  55. global usbblaster_name
  56. global test_device
  57. foreach hardware_name [get_hardware_names] {
  58. if { [string match "USB-Blaster*" $hardware_name] } {
  59. set usbblaster_name $hardware_name
  60. }
  61. }
  62. foreach device_name [get_device_names -hardware_name $usbblaster_name] {
  63. if { [string match "@1*" $device_name] } {
  64. set test_device $device_name
  65. }
  66. }
  67. puts "Connected: $hardware_name \n $device_name"
  68. }
  69. proc write_ctrl { val } {
  70. set_address FFF
  71. write_data [list $val]
  72. }
  73. ####################################################################
  74. if { $argc != 2} {
  75. puts "requires arguments: dmem.mif imem.mif"
  76. } else {
  77. connect_jtag
  78. write_ctrl 0
  79. download_file 000 [lindex $argv 0]
  80. download_file 400 [lindex $argv 1]
  81. write_ctrl 1
  82. }