Date:2011-10-11 17:02:58 (7 years 8 months ago)
Author:Werner Almesberger
Commit:04e7d1186d390732faed6c628793a206e50e2af5
Message:m1rc3/norruption/2/bcmp: compare bitstreams and highlight differences

Files: m1rc3/norruption/2/bscmp (1 diff)

Change Details

m1rc3/norruption/2/bscmp
1#!/usr/bin/perl
2
3$REF = "standby.fpg"; # reference bitstream
4$LEN = 0x78dd0; # cut off trailing junk
5
6open(FILE, $REF) || die "$REF: $!";
7$ref = substr(join("", <FILE>), 0, $LEN);
8close FILE;
9
10die "reference bitstream is too short" unless length $ref == $LEN;
11
12for (@ARGV) {
13    open(FILE, $_) || die "$_: $!";
14    $c{$_} = substr(join("", <FILE>), 0, $LEN);
15    close FILE;
16    die "$_ is too short" unless length $c{$_} == $LEN;
17}
18
19# @@@ not quite perfect - we should extract the cycle numbers and sort by them
20
21for (sort keys %c) {
22    $n = 0;
23    @a = ();
24    for ($i = 0; $i != $LEN; $i += 2) {
25        next unless substr($ref, $i, 2) ne substr($c{$_}, $i, 2);
26        $r = unpack("B*", substr($ref, $i, 2));
27        $c = unpack("B*", substr($c{$_}, $i, 2));
28        if (defined $s{$i}) {
29            $s = " " x 26;
30        } else {
31            $s = sprintf("%05x ", $i);
32            for ($j = 19; $j >= 0; $j--) {
33                $s .= $i & (1 << $j) ? "1" : "_";
34            }
35        }
36        $s .= " | ";
37        for ($j = 0; $j != 16; $j++) {
38            $s .= " " if $j == 8;
39            $s .= substr($r, $j, 1) ?
40                substr($c, $j, 1) ? "1" : "0" :
41                substr($c, $j, 1) ? die : "_";
42# substr($c, $j, 1) ? "\033[7m \033[m" : "_";
43        }
44        if ($i >= 0x10) { # count only fatal corruptions
45            push(@a, $i);
46            $n++;
47        } else {
48            $s .= " | $_\n";
49        }
50        $s{$i} .= $s;
51    }
52    for $a (@a) {
53        $s{$a} .= " | $_ ($n)\n";
54    }
55}
56
57for (sort { $a <=> $b } keys %s) {
58    print $s{$_};
59}

Archive Download the corresponding diff file

Branches:
master



interactive