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.
 
 
 
 
 
 

208 lines
6.1 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "arm_jtag.h"
  24. #include "binarybuffer.h"
  25. #include "log.h"
  26. #include "jtag.h"
  27. #include <stdlib.h>
  28. #if 0
  29. #define _ARM_JTAG_SCAN_N_CHECK_
  30. #endif
  31. int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr, in_handler_t handler)
  32. {
  33. jtag_device_t *device = jtag_get_device(jtag_info->chain_pos);
  34. if (buf_get_u32(device->cur_instr, 0, device->ir_length) != new_instr)
  35. {
  36. scan_field_t field;
  37. field.device = jtag_info->chain_pos;
  38. field.num_bits = device->ir_length;
  39. field.out_value = calloc(CEIL(field.num_bits, 8), 1);
  40. buf_set_u32(field.out_value, 0, field.num_bits, new_instr);
  41. field.out_mask = NULL;
  42. field.in_value = NULL;
  43. field.in_check_value = NULL;
  44. field.in_check_mask = NULL;
  45. field.in_handler = handler;
  46. field.in_handler_priv = NULL;
  47. jtag_add_ir_scan(1, &field, -1);
  48. free(field.out_value);
  49. }
  50. return ERROR_OK;
  51. }
  52. int arm_jtag_scann(arm_jtag_t *jtag_info, u32 new_scan_chain)
  53. {
  54. if(jtag_info->cur_scan_chain != new_scan_chain)
  55. {
  56. #ifdef _ARM_JTAG_SCAN_N_CHECK_
  57. u8 scan_n_check_value = 1 << (jtag_info->scann_size - 1);
  58. #endif
  59. scan_field_t field;
  60. field.device = jtag_info->chain_pos;
  61. field.num_bits = jtag_info->scann_size;
  62. field.out_value = calloc(CEIL(field.num_bits, 8), 1);
  63. buf_set_u32(field.out_value, 0, field.num_bits, new_scan_chain);
  64. field.out_mask = NULL;
  65. field.in_value = NULL;
  66. #ifdef _ARM_JTAG_SCAN_N_CHECK_
  67. jtag_set_check_value(&field, &scan_n_check_value, NULL, NULL, NULL);
  68. #else
  69. field.in_handler = NULL;
  70. field.in_handler_priv = NULL;
  71. #endif
  72. arm_jtag_set_instr(jtag_info, jtag_info->scann_instr, NULL);
  73. jtag_add_dr_scan(1, &field, -1);
  74. jtag_info->cur_scan_chain = new_scan_chain;
  75. free(field.out_value);
  76. }
  77. return ERROR_OK;
  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. jtag_register_event_callback(arm_jtag_reset_callback, jtag_info);
  94. return ERROR_OK;
  95. }
  96. /* read JTAG buffer into host-endian u32, flipping bit-order */
  97. int arm_jtag_buf_to_u32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  98. {
  99. u32 *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 u32, flipping bit-order */
  104. int arm_jtag_buf_to_le32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  105. {
  106. h_u32_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
  107. return ERROR_OK;
  108. }
  109. /* read JTAG buffer into little-endian u16, flipping bit-order */
  110. int arm_jtag_buf_to_le16_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  111. {
  112. h_u16_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
  113. return ERROR_OK;
  114. }
  115. /* read JTAG buffer into big-endian u32, flipping bit-order */
  116. int arm_jtag_buf_to_be32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  117. {
  118. h_u32_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
  119. return ERROR_OK;
  120. }
  121. /* read JTAG buffer into big-endian u16, flipping bit-order */
  122. int arm_jtag_buf_to_be16_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  123. {
  124. h_u16_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
  125. return ERROR_OK;
  126. }
  127. /* read JTAG buffer into u8, flipping bit-order */
  128. int arm_jtag_buf_to_8_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
  129. {
  130. u8 *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 u32 */
  136. int arm_jtag_buf_to_u32(u8 *in_buf, void *priv, struct scan_field_s *field)
  137. {
  138. u32 *dest = priv;
  139. *dest = le_to_h_u32(in_buf);
  140. return ERROR_OK;
  141. }
  142. /* read JTAG buffer into little-endian u32 */
  143. int arm_jtag_buf_to_le32(u8 *in_buf, void *priv, struct scan_field_s *field)
  144. {
  145. h_u32_to_le(((u8*)priv), le_to_h_u32(in_buf));
  146. return ERROR_OK;
  147. }
  148. /* read JTAG buffer into little-endian u16 */
  149. int arm_jtag_buf_to_le16(u8 *in_buf, void *priv, struct scan_field_s *field)
  150. {
  151. h_u16_to_le(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
  152. return ERROR_OK;
  153. }
  154. /* read JTAG buffer into big-endian u32 */
  155. int arm_jtag_buf_to_be32(u8 *in_buf, void *priv, struct scan_field_s *field)
  156. {
  157. h_u32_to_be(((u8*)priv), le_to_h_u32(in_buf));
  158. return ERROR_OK;
  159. }
  160. /* read JTAG buffer into big-endian u16 */
  161. int arm_jtag_buf_to_be16(u8 *in_buf, void *priv, struct scan_field_s *field)
  162. {
  163. h_u16_to_be(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
  164. return ERROR_OK;
  165. }
  166. /* read JTAG buffer into u8 */
  167. int arm_jtag_buf_to_8(u8 *in_buf, void *priv, struct scan_field_s *field)
  168. {
  169. u8 *dest = priv;
  170. *dest = le_to_h_u32(in_buf) & 0xff;
  171. return ERROR_OK;
  172. }