icepick.cfg 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #
  2. # Copyright (C) 2011 by Karl Kurbjun
  3. # Copyright (C) 2009 by David Brownell
  4. #
  5. # Utilities for TI ICEpick-C/D used in most TI SoCs
  6. # Details about the ICEPick are available in the the TRM for each SoC
  7. # and http://processors.wiki.ti.com/index.php/ICEPICK
  8. # create "constants"
  9. proc CONST { key } {
  10. array set constant {
  11. # define ICEPick instructions
  12. IR_BYPASS 0x00
  13. IR_ROUTER 0x02
  14. IR_CONNECT 0x07
  15. IF_BYPASS 0x3F
  16. }
  17. return $constant($key)
  18. }
  19. # Instruction to connect to the icepick module
  20. proc icepick_c_connect {jrc} {
  21. # Send CONNECT instruction in IR state
  22. irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
  23. # Send write and connect key
  24. drscan $jrc 8 0x89 -endstate DRPAUSE
  25. }
  26. # Instruction to disconnect to the icepick module
  27. proc icepick_c_disconnect {jrc} {
  28. # Send CONNECT instruction in IR state
  29. irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
  30. # Send write and connect key
  31. drscan $jrc 8 0x86 -endstate DRPAUSE
  32. }
  33. #
  34. # icepick_c_router:
  35. # this function is for sending router commands
  36. # arguments are:
  37. # jrc: TAP name for the ICEpick
  38. # rw: read/write (0 for read, 1 for write)
  39. # block: icepick or DAP
  40. # register: which register to read/write
  41. # payload: value to read/write
  42. # this function is for sending router commands
  43. #
  44. proc icepick_c_router {jrc rw block register payload} {
  45. set new_dr_value \
  46. [expr { ( ($rw & 0x1) << 31) | ( ($block & 0x7) << 28) | \
  47. ( ($register & 0xF) << 24) | ( $payload & 0xFFFFFF ) } ]
  48. # echo "\tNew router value:\t0x[format %x $new_dr_value]"
  49. # select router
  50. irscan $jrc [CONST IR_ROUTER] -endstate IRPAUSE
  51. # ROUTER instructions are 32 bits wide
  52. set old_dr_value 0x[drscan $jrc 32 $new_dr_value -endstate DRPAUSE]
  53. # echo "\tOld router value:\t0x[format %x $old_dr_value]"
  54. }
  55. # Configure the icepick control register
  56. proc icepick_c_setup {jrc} {
  57. # send a router write, block is 0, register is 1, value is 0x2100
  58. icepick_c_router $jrc 1 0x0 0x1 0x001000
  59. }
  60. # jrc == TAP name for the ICEpick
  61. # port == a port number, 0..15 for debug tap, 16..31 for test tap
  62. proc icepick_c_tapenable {jrc port} {
  63. if { ($port >= 0) && ($port < 16) } {
  64. # Debug tap"
  65. set tap $port
  66. set block 0x2
  67. } elseif { $port < 32 } {
  68. # Test tap
  69. set tap [expr {$port - 16}]
  70. set block 0x1
  71. } else {
  72. echo "ERROR: Invalid ICEPick C port number: $port"
  73. return
  74. }
  75. # First CONNECT to the ICEPick
  76. # echo "Connecting to ICEPick"
  77. icepick_c_connect $jrc
  78. # echo "Configuring the ICEpick"
  79. icepick_c_setup $jrc
  80. # NOTE: it's important not to enter RUN/IDLE state until
  81. # done sending these instructions and data to the ICEpick.
  82. # And never to enter RESET, which will disable the TAPs.
  83. # first enable power and clock for TAP
  84. icepick_c_router $jrc 1 $block $tap 0x110048
  85. # TRM states that the register should be read back here, skipped for now
  86. # enable debug "default" mode
  87. icepick_c_router $jrc 1 $block $tap 0x112048
  88. # TRM states that debug enable and debug mode should be read back and
  89. # confirmed - skipped for now
  90. # Finally select the tap
  91. icepick_c_router $jrc 1 $block $tap 0x112148
  92. # Enter the bypass state
  93. irscan $jrc [CONST IR_BYPASS] -endstate RUN/IDLE
  94. runtest 10
  95. }
  96. # jrc == TAP name for the ICEpick
  97. # coreid== core id number 0..15 (not same as port number!)
  98. proc icepick_d_set_core_control {jrc coreid value } {
  99. icepick_c_router $jrc 1 0x6 $coreid $value
  100. }
  101. # jrc == TAP name for the ICEpick
  102. # port == a port number, 0..15
  103. # Follow the sequence described in
  104. # http://processors.wiki.ti.com/images/f/f6/Router_Scan_Sequence-ICEpick-D.pdf
  105. proc icepick_d_tapenable {jrc port coreid { value 0x2008 } } {
  106. # First CONNECT to the ICEPick
  107. icepick_c_connect $jrc
  108. icepick_c_setup $jrc
  109. # Select the port
  110. icepick_c_router $jrc 1 0x2 $port 0x2108
  111. # Set icepick core control for $coreid
  112. icepick_d_set_core_control $jrc $coreid $value
  113. # Enter the bypass state
  114. irscan $jrc [CONST IF_BYPASS] -endstate RUN/IDLE
  115. runtest 10
  116. }
  117. # This function uses the ICEPick to send a warm system reset
  118. proc icepick_c_wreset {jrc} {
  119. # send a router write, block is 0, register is 1, value is 0x2100
  120. icepick_c_router $jrc 1 0x0 0x1 0x002101
  121. }