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.
 
 
 
 
 
 

203 lines
6.0 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. #include "binarybuffer.h"
  28. #include "log.h"
  29. #include "jtag.h"
  30. #include <stdlib.h>
  31. #if 0
  32. #define _ARM_JTAG_SCAN_N_CHECK_
  33. #endif
  34. int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr, in_handler_t handler)
  35. {
  36. jtag_device_t *device = jtag_get_device(jtag_info->chain_pos);
  37. if (device==NULL)
  38. return ERROR_FAIL;
  39. if (buf_get_u32(device->cur_instr, 0, device->ir_length) != new_instr)
  40. {
  41. scan_field_t field;
  42. u8 t[4];
  43. field.device = jtag_info->chain_pos;
  44. field.num_bits = device->ir_length;
  45. field.out_value = t;
  46. buf_set_u32(field.out_value, 0, field.num_bits, new_instr);
  47. field.out_mask = NULL;
  48. field.in_value = NULL;
  49. field.in_check_value = NULL;
  50. field.in_check_mask = NULL;
  51. field.in_handler = handler;
  52. field.in_handler_priv = NULL;
  53. jtag_add_ir_scan(1, &field, -1);
  54. }
  55. return ERROR_OK;
  56. }
  57. int arm_jtag_scann(arm_jtag_t *jtag_info, u32 new_scan_chain)
  58. {
  59. int retval = ERROR_OK;
  60. if(jtag_info->cur_scan_chain != new_scan_chain)
  61. {
  62. u32 values[1];
  63. int num_bits[1];
  64. values[0]=new_scan_chain;
  65. num_bits[0]=jtag_info->scann_size;
  66. if((retval = arm_jtag_set_instr(jtag_info, jtag_info->scann_instr, NULL)) != ERROR_OK)
  67. {
  68. return retval;
  69. }
  70. jtag_add_dr_out(jtag_info->chain_pos,
  71. 1,
  72. num_bits,
  73. values,
  74. -1);
  75. jtag_info->cur_scan_chain = new_scan_chain;
  76. }
  77. return retval;
  78. }
  79. int arm_jtag_reset_callback(enum jtag_event event, void *priv)
  80. {
  81. arm_jtag_t *jtag_info = priv;
  82. if (event == JTAG_TRST_ASSERTED)
  83. {
  84. jtag_info->cur_scan_chain = 0;
  85. }
  86. return ERROR_OK;
  87. }
  88. int arm_jtag_setup_connection(arm_jtag_t *jtag_info)
  89. {
  90. jtag_info->scann_instr = 0x2;
  91. jtag_info->cur_scan_chain = 0;
  92. jtag_info->intest_instr = 0xc;
  93. return jtag_register_event_callback(arm_jtag_reset_callback, jtag_info);
  94. }
  95. /* read JTAG buffer into host-endian u32, flipping bit-order */
  96. int arm_jtag_buf_to_u32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  97. {
  98. u32 *dest = priv;
  99. *dest = flip_u32(le_to_h_u32(in_buf), 32);
  100. return ERROR_OK;
  101. }
  102. /* read JTAG buffer into little-endian u32, flipping bit-order */
  103. int arm_jtag_buf_to_le32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  104. {
  105. h_u32_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
  106. return ERROR_OK;
  107. }
  108. /* read JTAG buffer into little-endian u16, flipping bit-order */
  109. int arm_jtag_buf_to_le16_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  110. {
  111. h_u16_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
  112. return ERROR_OK;
  113. }
  114. /* read JTAG buffer into big-endian u32, flipping bit-order */
  115. int arm_jtag_buf_to_be32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  116. {
  117. h_u32_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
  118. return ERROR_OK;
  119. }
  120. /* read JTAG buffer into big-endian u16, flipping bit-order */
  121. int arm_jtag_buf_to_be16_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  122. {
  123. h_u16_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
  124. return ERROR_OK;
  125. }
  126. /* read JTAG buffer into u8, flipping bit-order */
  127. int arm_jtag_buf_to_8_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  128. {
  129. u8 *dest = priv;
  130. *dest = flip_u32(le_to_h_u32(in_buf), 32) & 0xff;
  131. return ERROR_OK;
  132. }
  133. /* not-flipping variants */
  134. /* read JTAG buffer into host-endian u32 */
  135. int arm_jtag_buf_to_u32(u8 *in_buf, void *priv, struct scan_field_s *field)
  136. {
  137. u32 *dest = priv;
  138. *dest = le_to_h_u32(in_buf);
  139. return ERROR_OK;
  140. }
  141. /* read JTAG buffer into little-endian u32 */
  142. int arm_jtag_buf_to_le32(u8 *in_buf, void *priv, struct scan_field_s *field)
  143. {
  144. h_u32_to_le(((u8*)priv), le_to_h_u32(in_buf));
  145. return ERROR_OK;
  146. }
  147. /* read JTAG buffer into little-endian u16 */
  148. int arm_jtag_buf_to_le16(u8 *in_buf, void *priv, struct scan_field_s *field)
  149. {
  150. h_u16_to_le(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
  151. return ERROR_OK;
  152. }
  153. /* read JTAG buffer into big-endian u32 */
  154. int arm_jtag_buf_to_be32(u8 *in_buf, void *priv, struct scan_field_s *field)
  155. {
  156. h_u32_to_be(((u8*)priv), le_to_h_u32(in_buf));
  157. return ERROR_OK;
  158. }
  159. /* read JTAG buffer into big-endian u16 */
  160. int arm_jtag_buf_to_be16(u8 *in_buf, void *priv, struct scan_field_s *field)
  161. {
  162. h_u16_to_be(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
  163. return ERROR_OK;
  164. }
  165. /* read JTAG buffer into u8 */
  166. int arm_jtag_buf_to_8(u8 *in_buf, void *priv, struct scan_field_s *field)
  167. {
  168. u8 *dest = priv;
  169. *dest = le_to_h_u32(in_buf) & 0xff;
  170. return ERROR_OK;
  171. }