From ff8ab03f34e7dbf879e1c04a060613a5f45b663b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 5 Jul 2016 11:24:08 +0200 Subject: [PATCH] use INSTRUCTION_OPCODE from bsdl file --- openocd-jtag-boundary-scan.pl | 69 +++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/openocd-jtag-boundary-scan.pl b/openocd-jtag-boundary-scan.pl index 72f9ac7..c44a386 100755 --- a/openocd-jtag-boundary-scan.pl +++ b/openocd-jtag-boundary-scan.pl @@ -8,9 +8,11 @@ use IO::Socket::INET; use Storable; my $openocd_remote = shift @ARGV || 'picam:4444'; -my $bsdl_file = $ENV{BSDL} || '_3128at100.bsd'; -#$bsdl_file = '3064at44.bsd'; # XXX -my $tap = $ENV{TAP} || 'x300.tap'; +my $bsdl_file = $ENV{BSDL} || + 'EP4CE6E22.bsd'; +# '_3128at100.bsd'; +# '3064at44.bsd'; # XXX +my $tap = $ENV{TAP} || 'tb276.tap'; my $BOUNDARY_LENGTH = 288; my $entity; @@ -19,8 +21,12 @@ my $bit2pin; my $io2bit; my $pin2io; -my $in_pin_map = 0; -my $pin_map = ''; +my $parse; +my $parse_in = 0; +my $parse_regex = join('|', qw( + PIN_MAP_STRING + INSTRUCTION_OPCODE +)); $|=1; # flush stdout @@ -28,13 +34,13 @@ require 'gpio.pl'; open(my $bsdl, '<', $bsdl_file); while(<$bsdl>) { - if ( m/PIN_MAP_STRING/ ) { - $pin_map .= $_; - $in_pin_map = 1; - } elsif ( $in_pin_map ) { + if ( m/($parse_regex)/ ) { + $parse_in = $1; + $parse->{$1} .= $_; + } elsif ( $parse_in ) { next if m/^\s*--/; - $pin_map .= $_; - $in_pin_map = 0 if m/;/; + $parse->{$parse_in} .= $_; + $parse_in = 0 if m/;/; } elsif ( m/"(\d+)\s+\(BC_\d+,\s+(\S+),\s+(\S+)/ ) { $bit2pin->{$1} = [ $2, $3 ]; push @{ $io2bit->{$2} }, $1; @@ -52,9 +58,16 @@ close($bsdl); warn "# bit2pin = ",dump($bit2pin); warn "# io2bit = ",dump($io2bit); -$pin_map =~ s/"\s*\&\s*"/ /gs; -$pin_map =~ s/^.*?:=\s*"//; -$pin_map =~ s/"\s*;\s*$//s; +foreach my $chunk ( keys %$parse ) { + $parse->{$chunk} =~ s/"\s*\&\s*"/ /gs; # concat lines back to single line + $parse->{$chunk} =~ s/^.+?"//s; # strip upto first quote + $parse->{$chunk} =~ s/"\s*;.*?$//s; # strip everything after closing + $parse->{$chunk} =~ s/\s+/ /gs; +} + +warn "# parse = ",dump($parse); + +my $pin_map = $parse->{PIN_MAP_STRING} || die "no PIN_MAP_STRING in ",dump($parse); sub str_comma { my $t = shift; @@ -75,6 +88,24 @@ warn "# pin2io = ",dump( $pin2io ); #store \$pin2io, $bsdl_file . '.pin2io.storable'; store \$pin2io, $entity . '.pin2io.storable'; + +my $opcode; +my $o = $parse->{INSTRUCTION_OPCODE} || die "no INSTRUCTION_OPCODE in ",dump($parse); +warn "XXX [$o]"; + +foreach ( split(/\)\s*,\s*/, $o) ) { + s/\s+\(/ /g; + s/\s*\)\s*$//g; + warn "XXX [$_]\n"; + my ( $inst_opcode, $bin ) = split(/\s+/, $_); + $opcode->{$inst_opcode} = sprintf "0x%02x", eval '0b' . $bin; +} +warn "# opcode = ",dump($opcode); + +foreach (qw(SAMPLE EXTEST)) { + die "missing INSTRUCTION_OPCODE $_ in ",dump($opcode) unless $opcode->{$_}; +} + my $pin_desc; foreach my $pin_file ( glob "pins/$entity*.tsv" ) { open(my $fh, '<', $pin_file); @@ -189,7 +220,7 @@ sub bin2hex { my $BSR; # first sample -print $sock "irscan $tap 0x55\n"; # SAMPLE/PRELOAD +print $sock "irscan $tap $opcode->{SAMPLE}\n"; # SAMPLE/PRELOAD print $sock "drscan $tap $BOUNDARY_LENGTH 0\n"; while(1) { @@ -268,18 +299,18 @@ warn "XXX",length($old_bsr), " == ",length($b); diff_bits( $BSR, $b ), $/; -# print $sock "irscan $tap 0x55\n"; # SAMPLE/PRELOAD +# print $sock "irscan $tap $opcode->{SAMPLE}\n"; # SAMPLE/PRELOAD print $sock "drscan $tap $BOUNDARY_LENGTH 0x", bin2hex($b), "\n"; - print $sock "irscan $tap 0x00\n"; # EXTEST + print $sock "irscan $tap $opcode->{EXTEST}\n"; # EXTEST # print $sock "drscan $tap $BOUNDARY_LENGTH 0x", bin2hex($b), "\n"; } elsif ( $cmd =~ m/\?/ ) { $last_bits = ''; - print $sock "irscan $tap 0x55\n"; # SAMPLE/PRELOAD + print $sock "irscan $tap $opcode->{SAMPLE}\n"; # SAMPLE/PRELOAD print $sock "drscan $tap $BOUNDARY_LENGTH 0\n"; } else { gpio::cmd( $cmd ); - print $sock "irscan $tap 0x55\n"; # SAMPLE/PRELOAD + print $sock "irscan $tap $opcode->{SAMPLE}\n"; # SAMPLE/PRELOAD print $sock "drscan $tap $BOUNDARY_LENGTH 0\n"; } -- 2.20.1