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.
 
 
 
 
 
 

206 lines
6.2 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * Copyright (C) 2007,2008 Øyvind Harboe *
  6. * oyvind.harboe@zylin.com *
  7. * *
  8. * This program is free software; you can redistribute it and/or modify *
  9. * it under the terms of the GNU General Public License as published by *
  10. * the Free Software Foundation; either version 2 of the License, or *
  11. * (at your option) any later version. *
  12. * *
  13. * This program is distributed in the hope that it will be useful, *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU General Public License *
  19. * along with this program; if not, write to the *
  20. * Free Software Foundation, Inc., *
  21. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  22. ***************************************************************************/
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #endif
  26. #include "arm_jtag.h"
  27. #if 0
  28. #define _ARM_JTAG_SCAN_N_CHECK_
  29. #endif
  30. int arm_jtag_set_instr(arm_jtag_t *jtag_info, uint32_t new_instr, void *no_verify_capture)
  31. {
  32. jtag_tap_t *tap;
  33. tap = jtag_info->tap;
  34. if (tap == NULL)
  35. return ERROR_FAIL;
  36. if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr)
  37. {
  38. scan_field_t field;
  39. uint8_t t[4];
  40. field.tap = tap;
  41. field.num_bits = tap->ir_length;
  42. field.out_value = t;
  43. buf_set_u32(field.out_value, 0, field.num_bits, new_instr);
  44. field.in_value = NULL;
  45. if (no_verify_capture == NULL)
  46. {
  47. jtag_add_ir_scan(1, &field, jtag_get_end_state());
  48. } else
  49. {
  50. /* FIX!!!! this is a kludge!!! arm926ejs.c should reimplement this arm_jtag_set_instr to
  51. * have special verification code.
  52. */
  53. jtag_add_ir_scan_noverify(1, &field, jtag_get_end_state());
  54. }
  55. }
  56. return ERROR_OK;
  57. }
  58. int arm_jtag_scann(arm_jtag_t *jtag_info, uint32_t new_scan_chain)
  59. {
  60. int retval = ERROR_OK;
  61. if (jtag_info->cur_scan_chain != new_scan_chain)
  62. {
  63. uint32_t values[1];
  64. int num_bits[1];
  65. values[0]=new_scan_chain;
  66. num_bits[0]=jtag_info->scann_size;
  67. if ((retval = arm_jtag_set_instr(jtag_info, jtag_info->scann_instr, NULL)) != ERROR_OK)
  68. {
  69. return retval;
  70. }
  71. jtag_add_dr_out(jtag_info->tap,
  72. 1,
  73. num_bits,
  74. values,
  75. jtag_get_end_state());
  76. jtag_info->cur_scan_chain = new_scan_chain;
  77. }
  78. return retval;
  79. }
  80. int arm_jtag_reset_callback(enum jtag_event event, void *priv)
  81. {
  82. arm_jtag_t *jtag_info = priv;
  83. if (event == JTAG_TRST_ASSERTED)
  84. {
  85. jtag_info->cur_scan_chain = 0;
  86. }
  87. return ERROR_OK;
  88. }
  89. int arm_jtag_setup_connection(arm_jtag_t *jtag_info)
  90. {
  91. jtag_info->scann_instr = 0x2;
  92. jtag_info->cur_scan_chain = 0;
  93. jtag_info->intest_instr = 0xc;
  94. return jtag_register_event_callback(arm_jtag_reset_callback, jtag_info);
  95. }
  96. /* read JTAG buffer into host-endian uint32_t, flipping bit-order */
  97. int arm_jtag_buf_to_u32_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  98. {
  99. uint32_t *dest = priv;
  100. *dest = flip_u32(le_to_h_u32(in_buf), 32);
  101. return ERROR_OK;
  102. }
  103. /* read JTAG buffer into little-endian uint32_t, flipping bit-order */
  104. int arm_jtag_buf_to_le32_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  105. {
  106. h_u32_to_le(((uint8_t*)priv), flip_u32(le_to_h_u32(in_buf), 32));
  107. return ERROR_OK;
  108. }
  109. /* read JTAG buffer into little-endian uint16_t, flipping bit-order */
  110. int arm_jtag_buf_to_le16_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  111. {
  112. h_u16_to_le(((uint8_t*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
  113. return ERROR_OK;
  114. }
  115. /* read JTAG buffer into big-endian uint32_t, flipping bit-order */
  116. int arm_jtag_buf_to_be32_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  117. {
  118. h_u32_to_be(((uint8_t*)priv), flip_u32(le_to_h_u32(in_buf), 32));
  119. return ERROR_OK;
  120. }
  121. /* read JTAG buffer into big-endian uint16_t, flipping bit-order */
  122. int arm_jtag_buf_to_be16_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  123. {
  124. h_u16_to_be(((uint8_t*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
  125. return ERROR_OK;
  126. }
  127. /* read JTAG buffer into uint8_t, flipping bit-order */
  128. int arm_jtag_buf_to_8_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  129. {
  130. uint8_t *dest = priv;
  131. *dest = flip_u32(le_to_h_u32(in_buf), 32) & 0xff;
  132. return ERROR_OK;
  133. }
  134. /* not-flipping variants */
  135. /* read JTAG buffer into host-endian uint32_t */
  136. int arm_jtag_buf_to_u32(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  137. {
  138. uint32_t *dest = priv;
  139. *dest = le_to_h_u32(in_buf);
  140. return ERROR_OK;
  141. }
  142. /* read JTAG buffer into little-endian uint32_t */
  143. int arm_jtag_buf_to_le32(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  144. {
  145. h_u32_to_le(((uint8_t*)priv), le_to_h_u32(in_buf));
  146. return ERROR_OK;
  147. }
  148. /* read JTAG buffer into little-endian uint16_t */
  149. int arm_jtag_buf_to_le16(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  150. {
  151. h_u16_to_le(((uint8_t*)priv), le_to_h_u32(in_buf) & 0xffff);
  152. return ERROR_OK;
  153. }
  154. /* read JTAG buffer into big-endian uint32_t */
  155. int arm_jtag_buf_to_be32(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  156. {
  157. h_u32_to_be(((uint8_t*)priv), le_to_h_u32(in_buf));
  158. return ERROR_OK;
  159. }
  160. /* read JTAG buffer into big-endian uint16_t */
  161. int arm_jtag_buf_to_be16(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  162. {
  163. h_u16_to_be(((uint8_t*)priv), le_to_h_u32(in_buf) & 0xffff);
  164. return ERROR_OK;
  165. }
  166. /* read JTAG buffer into uint8_t */
  167. int arm_jtag_buf_to_8(uint8_t *in_buf, void *priv, struct scan_field_s *field)
  168. {
  169. uint8_t *dest = priv;
  170. *dest = le_to_h_u32(in_buf) & 0xff;
  171. return ERROR_OK;
  172. }