icepick.cfg 4.1 KB

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