~ubuntu-branches/ubuntu/wily/openocd/wily

« back to all changes in this revision

Viewing changes to src/xsvf/xsvf.c

  • Committer: Bazaar Package Importer
  • Author(s): Uwe Hermann
  • Date: 2009-11-25 12:20:04 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091125122004-4cnrzqw7v9qu064n
Tags: 0.3.1-1
* New upstream release (Closes: #554598, #537740).
* Add sh4 (instead of sh) to the list of architectures (Closes: #555553).
* Standards-Version: 3.8.3 (no changes required).
* debian/watch: Add file.
* debian/docs: Updates, some files were removed, some added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 *       Copyright (C) 2008 Peter Hettkamp                                                                         *
9
 
 *       peter.hettkamp@htp-tel.de                                                                                         *
10
 
 *                                                                                                                                                 *
11
 
 *       Copyright (C) 2009 SoftPLC Corporation. http://softplc.com             *
12
 
 *       Dick Hollenbeck <dick@softplc.com>                                                                        *
13
 
 *                                                                          *
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.                                                                       *
18
 
 *                                                                                                                                                 *
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.                                              *
23
 
 *                                                                                                                                                 *
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
 
 ***************************************************************************/
 
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
 * Copyright (C) 2008 Peter Hettkamp
 
9
 * peter.hettkamp@htp-tel.de
 
10
 *
 
11
 * Copyright (C) 2009 SoftPLC Corporation. http://softplc.com
 
12
 * Dick Hollenbeck <dick@softplc.com>
 
13
 *
 
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.
 
18
 *
 
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.
 
23
 
 
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
 
27
 */
29
28
 
30
29
 
31
30
/* The specification for SVF is available here:
43
42
 
44
43
#include "xsvf.h"
45
44
#include "jtag.h"
 
45
#include "svf.h"
46
46
 
47
47
 
48
48
/* XSVF commands, from appendix B of xapp503.pdf  */
186
186
 
187
187
static int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
188
188
{
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;
192
192
 
197
197
        tap_state_t     xendir = TAP_IDLE;              /* see page 8 of the SVF spec, initial xendir to be TAP_IDLE */
198
198
        tap_state_t xenddr = TAP_IDLE;
199
199
 
200
 
        uint8_t                 opcode;
 
200
        uint8_t         opcode;
201
201
        uint8_t         uc;
202
202
        long            file_offset = 0;
203
203
 
206
206
        int             loop_clocks = 0;
207
207
        int             loop_usecs = 0;
208
208
 
209
 
        int             do_abort = 0;
210
 
        int             unsupported = 0;
211
 
        int             tdo_mismatch = 0;
212
 
        int             result;
 
209
        int             do_abort = 0;
 
210
        int             unsupported = 0;
 
211
        int             tdo_mismatch = 0;
 
212
        int             result;
213
213
        int             verbose = 1;
214
 
        char*   filename;
215
 
 
216
 
        int             runtest_requires_tck = 0;       /* a flag telling whether to clock TCK during waits, or simply sleep, controled by virt2 */
 
214
        char            *filename;
 
215
 
 
216
        bool            collecting_path = false;
 
217
        tap_state_t     path[XSTATE_MAX_PATH];
 
218
        unsigned        pathlen = 0;
 
219
 
 
220
        /* a flag telling whether to clock TCK during waits,
 
221
         * or simply sleep, controled by virt2
 
222
         */
 
223
        int             runtest_requires_tck = 0;
217
224
 
218
225
 
219
226
        /* use NULL to indicate a "plain" xsvf file which accounts for
263
270
 
264
271
        while (read(xsvf_fd, &opcode, 1) > 0)
265
272
        {
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;
268
275
 
 
276
                /* maybe collect another state for a pathmove();
 
277
                 * or terminate a path.
 
278
                 */
 
279
                if (collecting_path) {
 
280
                        tap_state_t     mystate;
 
281
                        uint8_t         uc;
 
282
 
 
283
                        switch (opcode) {
 
284
                        case XCOMMENT:
 
285
                                /* ignore/show comments between XSTATE ops */
 
286
                                break;
 
287
                        case XSTATE:
 
288
                                /* try to collect another transition */
 
289
                                if (pathlen == XSTATE_MAX_PATH) {
 
290
                                        LOG_ERROR("XSVF: path too long");
 
291
                                        do_abort = 1;
 
292
                                        break;
 
293
                                }
 
294
 
 
295
                                if (read(xsvf_fd, &uc, 1) < 0)
 
296
                                {
 
297
                                        do_abort = 1;
 
298
                                        break;
 
299
                                }
 
300
 
 
301
                                mystate = xsvf_to_tap(uc);
 
302
                                path[pathlen++] = mystate;
 
303
 
 
304
                                LOG_DEBUG("XSTATE 0x%02X %s", uc,
 
305
                                                tap_state_name(mystate));
 
306
 
 
307
                                /* If path is incomplete, collect more */
 
308
                                if (!svf_tap_state_is_stable(mystate))
 
309
                                        continue;
 
310
 
 
311
                                /* Else execute the path transitions we've
 
312
                                 * collected so far.
 
313
                                 *
 
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.
 
322
                                 */
 
323
                                if (mystate == TAP_RESET) {
 
324
                                        LOG_WARNING("XSVF: dodgey RESET");
 
325
                                        path[0] = mystate;
 
326
                                }
 
327
 
 
328
                                /* FALL THROUGH */
 
329
                        default:
 
330
                                /* Execute the path we collected
 
331
                                 *
 
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.
 
336
                                 */
 
337
                                collecting_path = false;
 
338
 
 
339
                                if (path[0] == TAP_RESET)
 
340
                                        jtag_add_tlr();
 
341
                                else
 
342
                                        jtag_add_pathmove(pathlen, path);
 
343
 
 
344
                                result = jtag_get_error();
 
345
                                if (result != ERROR_OK) {
 
346
                                        LOG_ERROR("XSVF: pathmove error %d",
 
347
                                                        result);
 
348
                                        do_abort = 1;
 
349
                                        break;
 
350
                                }
 
351
                                continue;
 
352
                        }
 
353
                }
 
354
 
269
355
                switch (opcode)
270
356
                {
271
357
                case XCOMPLETE:
433
519
                                /* See page 19 of XSVF spec regarding opcode "XSDR" */
434
520
                                if (xruntest)
435
521
                                {
436
 
                                        jtag_add_statemove(TAP_IDLE);
 
522
                                        result = svf_add_statemove(TAP_IDLE);
437
523
 
438
524
                                        if (runtest_requires_tck)
439
525
                                                jtag_add_clocks(xruntest);
441
527
                                                jtag_add_sleep(xruntest);
442
528
                                }
443
529
                                else if (xendir != TAP_DRPAUSE) /* we are already in TAP_DRPAUSE */
444
 
                                        jtag_add_statemove(xenddr);
 
530
                                        result = svf_add_statemove(xenddr);
445
531
                        }
446
532
                        break;
447
533
 
500
586
 
501
587
                                LOG_DEBUG("XSTATE 0x%02X %s", uc, tap_state_name(mystate));
502
588
 
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
505
 
                                        the XSTATE.
506
 
                                */
507
 
 
508
 
                                if (jtag_add_statemove(mystate) != ERROR_OK)
 
589
                                if (mystate == TAP_INVALID) {
 
590
                                        LOG_ERROR("XSVF: bad XSTATE %02x", uc);
 
591
                                        do_abort = 1;
 
592
                                        break;
 
593
                                }
 
594
 
 
595
                                /* NOTE: the current state is SVF-stable! */
 
596
 
 
597
                                /* no change == NOP */
 
598
                                if (mystate == cmd_queue_cur_state
 
599
                                                && mystate != TAP_RESET)
 
600
                                        break;
 
601
 
 
602
                                /* Hand off to SVF? */
 
603
                                if (svf_tap_state_is_stable(mystate))
509
604
                                {
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
521
 
                                                state path.
522
 
                                        */
 
605
                                        result = svf_add_statemove(mystate);
 
606
                                        if (result != ERROR_OK)
 
607
                                                unsupported = 1;
 
608
                                        break;
 
609
                                }
523
610
 
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)
527
 
);
528
 
                                }
 
611
                                /*
 
612
                                 * A sequence of XSTATE transitions, each TAP
 
613
                                 * state adjacent to the previous one.  Start
 
614
                                 * collecting them.
 
615
                                 */
 
616
                                collecting_path = true;
 
617
                                pathlen = 1;
 
618
                                path[0] = mystate;
529
619
                        }
530
620
                        break;
531
621
 
654
744
                case XCOMMENT:
655
745
                        {
656
746
                                unsigned int ndx = 0;
657
 
                                char    comment[128];
 
747
                                char    comment[128];
658
748
 
659
749
                                do
660
750
                                {
687
777
 
688
778
                                tap_state_t wait_state;
689
779
                                tap_state_t end_state;
690
 
                                int     delay;
 
780
                                int     delay;
691
781
 
692
782
                                if (read(xsvf_fd, &wait, 1) < 0
693
783
                                  || read(xsvf_fd, &end, 1) < 0
709
799
                                }
710
800
                                else
711
801
                                {
712
 
                                        jtag_add_statemove(wait_state);
 
802
                                        /* FIXME handle statemove errors ... */
 
803
                                        result = svf_add_statemove(wait_state);
713
804
                                        jtag_add_sleep(delay);
714
 
                                        jtag_add_statemove(end_state);
 
805
                                        result = svf_add_statemove(end_state);
715
806
                                }
716
807
                        }
717
808
                        break;
723
814
                                */
724
815
 
725
816
                                uint8_t  clock_buf[4];
726
 
                                uint8_t         usecs_buf[4];
 
817
                                uint8_t usecs_buf[4];
727
818
                                uint8_t wait;
728
819
                                uint8_t end;
729
820
                                tap_state_t wait_state;
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.
758
849
                                 */
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))
760
851
                                {
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));
762
854
                                        unsupported = 1;
 
855
                                        /* REVISIT "break" so we won't run? */
763
856
                                }
764
857
 
765
 
                                jtag_add_statemove(wait_state);
 
858
                                /* FIXME handle statemove errors ... */
 
859
                                result = svf_add_statemove(wait_state);
766
860
 
767
861
                                jtag_add_clocks(clock_count);
768
862
 
769
863
                                jtag_add_sleep(usecs);
770
864
 
771
 
                                jtag_add_statemove(end_state);
 
865
                                result = svf_add_statemove(end_state);
772
866
                        }
773
867
                        break;
774
868
 
807
901
                                        break;
808
902
                                }
809
903
 
 
904
                                /* NOTE:  loop_state must be stable! */
810
905
                                loop_state  = xsvf_to_tap(state);
811
906
                                loop_clocks = be_to_h_u32(clock_buf);
812
907
                                loop_usecs  = be_to_h_u32(usecs_buf);
840
935
                                {
841
936
                                        scan_field_t field;
842
937
 
843
 
                                        jtag_add_statemove(loop_state);
 
938
                                        result = svf_add_statemove(loop_state);
844
939
                                        jtag_add_clocks(loop_clocks);
845
940
                                        jtag_add_sleep(loop_usecs);
846
941
 
918
1013
                        LOG_DEBUG("xsvf failed, setting taps to reasonable state");
919
1014
 
920
1015
                        /* upon error, return the TAPs to a reasonable state */
921
 
                        jtag_add_statemove(TAP_IDLE);
922
 
                        jtag_execute_queue();
 
1016
                        result = svf_add_statemove(TAP_IDLE);
 
1017
                        result = jtag_execute_queue();
923
1018
                        break;
924
1019
                }
925
1020
        }