From 04e7d1186d390732faed6c628793a206e50e2af5 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 11 Oct 2011 12:02:58 -0300 Subject: [PATCH] m1rc3/norruption/2/bcmp: compare bitstreams and highlight differences --- m1rc3/norruption/2/bscmp | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 m1rc3/norruption/2/bscmp diff --git a/m1rc3/norruption/2/bscmp b/m1rc3/norruption/2/bscmp new file mode 100755 index 0000000..6478344 --- /dev/null +++ b/m1rc3/norruption/2/bscmp @@ -0,0 +1,59 @@ +#!/usr/bin/perl + +$REF = "standby.fpg"; # reference bitstream +$LEN = 0x78dd0; # cut off trailing junk + +open(FILE, $REF) || die "$REF: $!"; +$ref = substr(join("", ), 0, $LEN); +close FILE; + +die "reference bitstream is too short" unless length $ref == $LEN; + +for (@ARGV) { + open(FILE, $_) || die "$_: $!"; + $c{$_} = substr(join("", ), 0, $LEN); + close FILE; + die "$_ is too short" unless length $c{$_} == $LEN; +} + +# @@@ not quite perfect - we should extract the cycle numbers and sort by them + +for (sort keys %c) { + $n = 0; + @a = (); + for ($i = 0; $i != $LEN; $i += 2) { + next unless substr($ref, $i, 2) ne substr($c{$_}, $i, 2); + $r = unpack("B*", substr($ref, $i, 2)); + $c = unpack("B*", substr($c{$_}, $i, 2)); + if (defined $s{$i}) { + $s = " " x 26; + } else { + $s = sprintf("%05x ", $i); + for ($j = 19; $j >= 0; $j--) { + $s .= $i & (1 << $j) ? "1" : "_"; + } + } + $s .= " | "; + for ($j = 0; $j != 16; $j++) { + $s .= " " if $j == 8; + $s .= substr($r, $j, 1) ? + substr($c, $j, 1) ? "1" : "0" : + substr($c, $j, 1) ? die : "_"; +# substr($c, $j, 1) ? "\033[7m \033[m" : "_"; + } + if ($i >= 0x10) { # count only fatal corruptions + push(@a, $i); + $n++; + } else { + $s .= " | $_\n"; + } + $s{$i} .= $s; + } + for $a (@a) { + $s{$a} .= " | $_ ($n)\n"; + } +} + +for (sort { $a <=> $b } keys %s) { + print $s{$_}; +}