1
/***************************************************************************
2
* Copyright (C) 2005 by Dominic Rath *
3
* Dominic.Rath@gmx.de *
5
* Copyright (C) 2007,2008 �yvind Harboe *
6
* oyvind.harboe@zylin.com *
8
* Copyright (C) 2008 Peter Hettkamp *
9
* peter.hettkamp@htp-tel.de *
11
* Copyright (C) 2009 SoftPLC Corporation. http://softplc.com *
12
* Dick Hollenbeck <dick@softplc.com> *
14
* This program is free software; you can redistribute it and/or modify *
15
* it under the terms of the GNU General Public License as published by *
16
* the Free Software Foundation; either version 2 of the License, or *
17
* (at your option) any later version. *
19
* This program is distributed in the hope that it will be useful, *
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22
* GNU General Public License for more details. *
24
* You should have received a copy of the GNU General Public License *
25
* along with this program; if not, write to the *
26
* Free Software Foundation, Inc., *
27
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28
***************************************************************************/
2
* Copyright (C) 2005 by Dominic Rath
5
* Copyright (C) 2007,2008 Øyvind Harboe
6
* oyvind.harboe@zylin.com
8
* Copyright (C) 2008 Peter Hettkamp
9
* peter.hettkamp@htp-tel.de
11
* Copyright (C) 2009 SoftPLC Corporation. http://softplc.com
12
* Dick Hollenbeck <dick@softplc.com>
14
* This program is free software; you can redistribute it and/or modify
15
* it under the terms of the GNU General Public License as published by
16
* the Free Software Foundation; either version 2 of the License, or
17
* (at your option) any later version.
19
* This program is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU General Public License for more details.
24
* You should have received a copy of the GNU General Public License
25
* along with this program; if not, write to the Free Software
26
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
30
/* The specification for SVF is available here:
187
187
static int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
189
uint8_t *dr_out_buf = NULL; /* from host to device (TDI) */
189
uint8_t *dr_out_buf = NULL; /* from host to device (TDI) */
190
190
uint8_t *dr_in_buf = NULL; /* from device to host (TDO) */
191
191
uint8_t *dr_in_mask = NULL;
206
206
int loop_clocks = 0;
207
207
int loop_usecs = 0;
211
int tdo_mismatch = 0;
211
int tdo_mismatch = 0;
216
int runtest_requires_tck = 0; /* a flag telling whether to clock TCK during waits, or simply sleep, controled by virt2 */
216
bool collecting_path = false;
217
tap_state_t path[XSTATE_MAX_PATH];
218
unsigned pathlen = 0;
220
/* a flag telling whether to clock TCK during waits,
221
* or simply sleep, controled by virt2
223
int runtest_requires_tck = 0;
219
226
/* use NULL to indicate a "plain" xsvf file which accounts for
264
271
while (read(xsvf_fd, &opcode, 1) > 0)
266
/* record the position of the just read opcode within the file */
273
/* record the position of this opcode within the file */
267
274
file_offset = lseek(xsvf_fd, 0, SEEK_CUR) - 1;
276
/* maybe collect another state for a pathmove();
277
* or terminate a path.
279
if (collecting_path) {
285
/* ignore/show comments between XSTATE ops */
288
/* try to collect another transition */
289
if (pathlen == XSTATE_MAX_PATH) {
290
LOG_ERROR("XSVF: path too long");
295
if (read(xsvf_fd, &uc, 1) < 0)
301
mystate = xsvf_to_tap(uc);
302
path[pathlen++] = mystate;
304
LOG_DEBUG("XSTATE 0x%02X %s", uc,
305
tap_state_name(mystate));
307
/* If path is incomplete, collect more */
308
if (!svf_tap_state_is_stable(mystate))
311
/* Else execute the path transitions we've
314
* NOTE: Punting on the saved path is not
315
* strictly correct, but we must to do this
316
* unless jtag_add_pathmove() stops rejecting
317
* paths containing RESET. This is probably
318
* harmless, since there aren't many options
319
* for going from a stable state to reset;
320
* at the worst, we may issue extra clocks
321
* once we get to RESET.
323
if (mystate == TAP_RESET) {
324
LOG_WARNING("XSVF: dodgey RESET");
330
/* Execute the path we collected
332
* NOTE: OpenOCD requires something that XSVF
333
* doesn't: the last TAP state in the path
334
* must be stable. In practice, tools that
335
* create XSVF seem to follow that rule too.
337
collecting_path = false;
339
if (path[0] == TAP_RESET)
342
jtag_add_pathmove(pathlen, path);
344
result = jtag_get_error();
345
if (result != ERROR_OK) {
346
LOG_ERROR("XSVF: pathmove error %d",
501
587
LOG_DEBUG("XSTATE 0x%02X %s", uc, tap_state_name(mystate));
503
/* there is no need for the lookahead code that was here since we
504
queue up the jtag commands anyway. This is a simple way to handle
508
if (jtag_add_statemove(mystate) != ERROR_OK)
589
if (mystate == TAP_INVALID) {
590
LOG_ERROR("XSVF: bad XSTATE %02x", uc);
595
/* NOTE: the current state is SVF-stable! */
597
/* no change == NOP */
598
if (mystate == cmd_queue_cur_state
599
&& mystate != TAP_RESET)
602
/* Hand off to SVF? */
603
if (svf_tap_state_is_stable(mystate))
510
/* For special states known as stable states
511
(Test-Logic-Reset, Run-Test/Idle, Pause-DR, Pause- IR),
512
an XSVF interpreter follows predefined TAP state paths
513
when the starting state is a stable state and when the
514
XSTATE specifies a new stable state (see the STATE
515
command in the [Ref 5] for the TAP state paths between
516
stable states). For non-stable states, XSTATE should
517
specify a state that is only one TAP state transition
518
distance from the current TAP state to avoid undefined
519
TAP state paths. A sequence of multiple XSTATE commands
520
can be issued to transition the TAP through a specific
605
result = svf_add_statemove(mystate);
606
if (result != ERROR_OK)
524
LOG_ERROR("XSTATE %s is not reachable from current state %s in one clock cycle",
525
tap_state_name(mystate),
526
tap_state_name(cmd_queue_cur_state)
612
* A sequence of XSTATE transitions, each TAP
613
* state adjacent to the previous one. Start
616
collecting_path = true;
756
847
* be issuing a number of clocks in this state. This set of allowed states is also
757
848
* determined by the SVF RUNTEST command's allowed states.
759
if (wait_state != TAP_IRPAUSE && wait_state != TAP_DRPAUSE && wait_state != TAP_RESET && wait_state != TAP_IDLE)
850
if (!svf_tap_state_is_stable(wait_state))
761
LOG_ERROR("illegal XWAITSTATE wait_state: \"%s\"", tap_state_name(wait_state));
852
LOG_ERROR("illegal XWAITSTATE wait_state: \"%s\"",
853
tap_state_name(wait_state));
855
/* REVISIT "break" so we won't run? */
765
jtag_add_statemove(wait_state);
858
/* FIXME handle statemove errors ... */
859
result = svf_add_statemove(wait_state);
767
861
jtag_add_clocks(clock_count);
769
863
jtag_add_sleep(usecs);
771
jtag_add_statemove(end_state);
865
result = svf_add_statemove(end_state);