fix diff_buts for BOUNDARY_LENGTH which are not multiple of 8 bits
[x300-pci] / openocd-jtag-boundary-scan.pl
index 4e3632c..3634bbe 100755 (executable)
@@ -251,19 +251,22 @@ while (<$sock>) {
 
 sub diff_bits {
        my ($old, $new) = @_;
+       $old = reverse $old; # extra bits must be on the end
+       $new = reverse $new;
        $old =~ s/(...)/$1 /g;
        $new =~ s/(...)/$1 /g;
        my @o = split(/ /, $old);
        my @n = split(/ /, $new);
-       foreach my $i ( 0 .. $#o ) {
+       my $bsr_max_bit = $BOUNDARY_LENGTH / 3 - 1;
+       foreach my $i ( 0 .. $bsr_max_bit ) {
                if ( $o[$i] eq $n[$i] ) {
                        $o[$i]='.';
                } else {
-                       my $pin = $bit2pin->{ $BOUNDARY_LENGTH - ($i * 3) - 3 }->[0];
+                       my $pin = $bit2pin->{ $i * 3 }->[0];
                        $o[$i] = " $pin@" . ( $i * 3 ) . ":" . $o[$i] . '>' . $n[$i];
                }
        }
-       my $diff = join('', @o);
+       my $diff = join('', @o[ 0 .. $bsr_max_bit ]);
        print "# diff_bits $diff\n";
 }