diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-10-29 20:41:57 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-10-29 20:41:57 +0100 |
commit | 22632c21ac4ff971445854c6bda3349514496e92 (patch) | |
tree | f9903d3adda4dafcfbe693040f1366e666475d29 | |
parent | ca1067965b24308e086cf50091b33cb99041c043 (diff) |
Add checksum fix script from PhotonSaw project.
-rwxr-xr-x | firmware/fix-lpcchecksum | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/firmware/fix-lpcchecksum b/firmware/fix-lpcchecksum new file mode 100755 index 0000000..5c57871 --- /dev/null +++ b/firmware/fix-lpcchecksum @@ -0,0 +1,33 @@ +#!/usr/bin/perl +use strict; +use warnings; +use FindBin qw($Bin $Script); + +my ($bfn) = @ARGV; +die "Syntax: $Script <bin file to fix>" unless $bfn and -f $bfn; + +open BIN, "<$bfn" or die "Unable to read $bfn: $!"; +my $vectors; +read(BIN, $vectors, 8*4) == 8*4 or die "Failed to read vectors"; +my @vectors = unpack("L"x8, $vectors); +print "Existing vectors: ".join(' ', map {sprintf("%08x", $_)} @vectors[0..6])."\n"; +close BIN; +print "Existing checksum: ".sprintf("%08x", $vectors[7])."\n"; + +my $cs = 0; +for my $v (@vectors[0..6]) { + $cs -= $v; +} + +$cs &= 0xffffffff; + +print "Correct checksum: ".sprintf("%08x", $cs)."\n"; + +if ($cs ne $vectors[7]) { + print "Fixing checksum\n"; + + open BIN, "+<$bfn" or die "Unable to write $bfn: $!"; + seek(BIN, 7*4, 0); + print BIN pack("L", $cs); + close BIN; +} |