You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

196 lines
4.7 KiB

  1. # Defines basic Tcl procs for OpenOCD target module
  2. proc new_target_name { } {
  3. return [target number [expr [target count] - 1 ]]
  4. }
  5. global in_process_reset
  6. set in_process_reset 0
  7. # Catch reset recursion
  8. proc ocd_process_reset { MODE } {
  9. global in_process_reset
  10. if {$in_process_reset} {
  11. set in_process_reset 0
  12. return -code error "'reset' can not be invoked recursively"
  13. }
  14. set in_process_reset 1
  15. set success [expr [catch {ocd_process_reset_inner $MODE} result]==0]
  16. set in_process_reset 0
  17. if {$success} {
  18. return $result
  19. } else {
  20. return -code error $result
  21. }
  22. }
  23. proc ocd_process_reset_inner { MODE } {
  24. set targets [target names]
  25. # If this target must be halted...
  26. set halt -1
  27. if { 0 == [string compare $MODE halt] } {
  28. set halt 1
  29. }
  30. if { 0 == [string compare $MODE init] } {
  31. set halt 1;
  32. }
  33. if { 0 == [string compare $MODE run ] } {
  34. set halt 0;
  35. }
  36. if { $halt < 0 } {
  37. return -code error "Invalid mode: $MODE, must be one of: halt, init, or run";
  38. }
  39. # Target event handlers *might* change which TAPs are enabled
  40. # or disabled, so we fire all of them. But don't issue any
  41. # target "arp_*" commands, which may issue JTAG transactions,
  42. # unless we know the underlying TAP is active.
  43. #
  44. # NOTE: ARP == "Advanced Reset Process" ... "advanced" is
  45. # relative to a previous restrictive scheme
  46. foreach t $targets {
  47. # New event script.
  48. $t invoke-event reset-start
  49. }
  50. # Use TRST or TMS/TCK operations to reset all the tap controllers.
  51. # TAP reset events get reported; they might enable some taps.
  52. init_reset $MODE
  53. # Examine all targets on enabled taps.
  54. foreach t $targets {
  55. if {[jtag tapisenabled [$t cget -chain-position]]} {
  56. $t invoke-event examine-start
  57. set err [catch "$t arp_examine"]
  58. if { $err == 0 } {
  59. $t invoke-event examine-end
  60. }
  61. }
  62. }
  63. # Assert SRST, and report the pre/post events.
  64. # Note: no target sees SRST before "pre" or after "post".
  65. foreach t $targets {
  66. $t invoke-event reset-assert-pre
  67. }
  68. foreach t $targets {
  69. # C code needs to know if we expect to 'halt'
  70. if {[jtag tapisenabled [$t cget -chain-position]]} {
  71. $t arp_reset assert $halt
  72. }
  73. }
  74. foreach t $targets {
  75. $t invoke-event reset-assert-post
  76. }
  77. # Now de-assert SRST, and report the pre/post events.
  78. # Note: no target sees !SRST before "pre" or after "post".
  79. foreach t $targets {
  80. $t invoke-event reset-deassert-pre
  81. }
  82. foreach t $targets {
  83. # Again, de-assert code needs to know if we 'halt'
  84. if {[jtag tapisenabled [$t cget -chain-position]]} {
  85. $t arp_reset deassert $halt
  86. }
  87. }
  88. foreach t $targets {
  89. $t invoke-event reset-deassert-post
  90. }
  91. # Pass 1 - Now wait for any halt (requested as part of reset
  92. # assert/deassert) to happen. Ideally it takes effect without
  93. # first executing any instructions.
  94. if { $halt } {
  95. foreach t $targets {
  96. if {[jtag tapisenabled [$t cget -chain-position]] == 0} {
  97. continue
  98. }
  99. # Wait upto 1 second for target to halt. Why 1sec? Cause
  100. # the JTAG tap reset signal might be hooked to a slow
  101. # resistor/capacitor circuit - and it might take a while
  102. # to charge
  103. # Catch, but ignore any errors.
  104. catch { $t arp_waitstate halted 1000 }
  105. # Did we succeed?
  106. set s [$t curstate]
  107. if { 0 != [string compare $s "halted" ] } {
  108. return -code error [format "TARGET: %s - Not halted" $t]
  109. }
  110. }
  111. }
  112. #Pass 2 - if needed "init"
  113. if { 0 == [string compare init $MODE] } {
  114. foreach t $targets {
  115. if {[jtag tapisenabled [$t cget -chain-position]] == 0} {
  116. continue
  117. }
  118. set err [catch "$t arp_waitstate halted 5000"]
  119. # Did it halt?
  120. if { $err == 0 } {
  121. $t invoke-event reset-init
  122. }
  123. }
  124. }
  125. foreach t $targets {
  126. $t invoke-event reset-end
  127. }
  128. }
  129. #########
  130. # Temporary migration aid. May be removed starting in January 2011.
  131. proc armv4_5 params {
  132. echo "DEPRECATED! use 'arm $params' not 'armv4_5 $params'"
  133. arm $params
  134. }
  135. # Target/chain configuration scripts can either execute commands directly
  136. # or define a procedure which is executed once all configuration
  137. # scripts have completed.
  138. #
  139. # By default(classic) the config scripts will set up the target configuration
  140. proc init_targets {} {
  141. }
  142. proc set_default_target_event {t e s} {
  143. if {[$t cget -event $e] == ""} {
  144. $t configure -event $e $s
  145. }
  146. }
  147. proc init_target_events {} {
  148. set targets [target names]
  149. foreach t $targets {
  150. set_default_target_event $t gdb-flash-erase-start "reset init"
  151. set_default_target_event $t gdb-flash-write-end "reset halt"
  152. }
  153. }
  154. # Additionally board config scripts can define a procedure init_board that will be executed after init and init_targets
  155. proc init_board {} {
  156. }
  157. # deprecated target name cmds
  158. proc cortex_m3 args {
  159. echo "DEPRECATED! use 'cortex_m' not 'cortex_m3'"
  160. eval cortex_m $args
  161. }
  162. proc cortex_a8 args {
  163. echo "DEPRECATED! use 'cortex_a' not 'cortex_a8'"
  164. eval cortex_a $args
  165. }