2525#include "protocol/host_cmd.h"
2626#include "protocol/jtag.h"
2727
28- // Used if no data is provided for data to send over TDI
29- static char * JTAG_TEST_BYPASS_PATTERN_DEFAULT_VALUE =
28+ // Used if no data is provided for data to send over TDI. This needs to be
29+ // modifiable for use with `strtok_r` later
30+ static char JTAG_TEST_BYPASS_PATTERN_DEFAULT_VALUE [] =
3031 // PRBS9 with '0' bit added at the beginning to make it exactly 64 bytes
3132 "0x42 0x30 0x9c 0xab 0xd 0xe9 0xb9 0x14 0x2b 0x4f 0xd9 0x25 0xbf 0x26 0xa6 "
3233 "0x60 0x31 0x94 0x69 0x7f 0x45 0x8e 0xb2 0xcf 0x1f 0x74 0x1a 0xdb 0xb0 "
@@ -37,19 +38,27 @@ static char *JTAG_TEST_BYPASS_PATTERN_DEFAULT_VALUE =
3738static int jtag_read_idcode (struct libhoth_device * dev ,
3839 const struct htool_invocation * inv ) {
3940 uint32_t clk_idiv ;
41+ uint32_t interface_id ;
4042
4143 if (htool_get_param_u32 (inv , "clk_idiv" , & clk_idiv )) {
4244 return -1 ;
4345 }
44-
4546 if (clk_idiv > UINT16_MAX ) {
4647 fprintf (stderr , "Clock divisor value too large. Expected <= %u\n" ,
4748 UINT16_MAX );
4849 return -1 ;
4950 }
5051
52+ if (htool_get_param_u32 (inv , "jtag_interface_id" , & interface_id )) {
53+ return -1 ;
54+ }
55+ if (interface_id > UINT8_MAX ) {
56+ fprintf (stderr , "Jtag ID value too large. Expected <= %u\n" , UINT8_MAX );
57+ return -1 ;
58+ }
59+
5160 uint32_t idcode = 0 ;
52- int ret = libhoth_jtag_read_idcode (dev , clk_idiv , & idcode );
61+ int ret = libhoth_jtag_read_idcode (dev , interface_id , clk_idiv , & idcode );
5362 if (ret != 0 ) {
5463 return ret ;
5564 }
@@ -100,6 +109,7 @@ static int jtag_test_bypass(struct libhoth_device *dev,
100109 const struct htool_invocation * inv ) {
101110 char * tdi_bytes_str = NULL ;
102111 uint32_t clk_idiv ;
112+ uint32_t interface_id ;
103113
104114 if (htool_get_param_u32 (inv , "clk_idiv" , & clk_idiv ) ||
105115 htool_get_param_string (inv , "tdi_bytes" , (const char * * )& tdi_bytes_str )) {
@@ -118,6 +128,14 @@ static int jtag_test_bypass(struct libhoth_device *dev,
118128 return -1 ;
119129 }
120130
131+ if (htool_get_param_u32 (inv , "jtag_interface_id" , & interface_id )) {
132+ return -1 ;
133+ }
134+ if (interface_id > UINT8_MAX ) {
135+ fprintf (stderr , "Jtag ID value too large. Expected <= %u\n" , UINT8_MAX );
136+ return -1 ;
137+ }
138+
121139 uint8_t tdi_bytes [HOTH_JTAG_TEST_BYPASS_PATTERN_LEN ];
122140 int ret = parse_string_param_into_byte_sequence (
123141 tdi_bytes_str , tdi_bytes , HOTH_JTAG_TEST_BYPASS_PATTERN_LEN );
@@ -132,7 +150,8 @@ static int jtag_test_bypass(struct libhoth_device *dev,
132150 printf ("\n" );
133151
134152 uint8_t tdo_bytes [HOTH_JTAG_TEST_BYPASS_PATTERN_LEN ] = {0 };
135- ret = libhoth_jtag_test_bypass (dev , clk_idiv , tdi_bytes , tdo_bytes );
153+ ret = libhoth_jtag_test_bypass (dev , interface_id , clk_idiv , tdi_bytes ,
154+ tdo_bytes );
136155 if (ret != 0 ) {
137156 return ret ;
138157 }
@@ -155,23 +174,41 @@ static int jtag_test_bypass(struct libhoth_device *dev,
155174static int jtag_program_and_verify_pld (struct libhoth_device * dev ,
156175 const struct htool_invocation * inv ) {
157176 uint32_t offset ;
177+ uint32_t interface_id ;
158178
159179 if (htool_get_param_u32 (inv , "offset" , & offset )) {
160180 return -1 ;
161181 }
162182
163- return libhoth_jtag_program_and_verify_pld (dev , offset );
183+ if (htool_get_param_u32 (inv , "jtag_interface_id" , & interface_id )) {
184+ return -1 ;
185+ }
186+ if (interface_id > UINT8_MAX ) {
187+ fprintf (stderr , "Jtag ID value too large. Expected <= %u\n" , UINT8_MAX );
188+ return -1 ;
189+ }
190+
191+ return libhoth_jtag_program_and_verify_pld (dev , interface_id , offset );
164192}
165193
166194static int jtag_verify_pld (struct libhoth_device * dev ,
167195 const struct htool_invocation * inv ) {
168196 uint32_t offset ;
197+ uint32_t interface_id ;
169198
170199 if (htool_get_param_u32 (inv , "offset" , & offset )) {
171200 return -1 ;
172201 }
173202
174- return libhoth_jtag_verify_pld (dev , offset );
203+ if (htool_get_param_u32 (inv , "jtag_interface_id" , & interface_id )) {
204+ return -1 ;
205+ }
206+ if (interface_id > UINT8_MAX ) {
207+ fprintf (stderr , "Jtag ID value too large. Expected <= %u\n" , UINT8_MAX );
208+ return -1 ;
209+ }
210+
211+ return libhoth_jtag_verify_pld (dev , interface_id , offset );
175212}
176213
177214int htool_jtag_run (const struct htool_invocation * inv ) {
0 commit comments