From 35d88b4d1fb08a99dd75a1446dc42718de166f45 Mon Sep 17 00:00:00 2001 From: Michael McMaster Date: Mon, 4 May 2015 20:21:28 +1000 Subject: [PATCH] Add tool to allow manual hacking of .hex firmware files --- tools/hexChecksum.pl | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tools/hexChecksum.pl diff --git a/tools/hexChecksum.pl b/tools/hexChecksum.pl new file mode 100644 index 0000000..d2fd369 --- /dev/null +++ b/tools/hexChecksum.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl -w +# Copyright (C) 2014 Michael McMaster +# +# This file is part of SCSI2SD. +# +# SCSI2SD is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# SCSI2SD is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with SCSI2SD. If not, see . + +# Calculates the checksum of all flash data within Cypress PSoC 5lp .hex files +# Allows fixing the checksum after manual hacking of the hex files + +use strict; +use warnings; + +my $sum = 0; +while (my $line = <>) +{ + + $line =~ s/[\n\r]//g; + + if ($line =~ /^:40[0-9A-F]{4}00(.+)[0-9A-F]{2}$/) + { + my $binrec = pack('H*', $1); + $sum += unpack('%16C*', $binrec); + } + elsif ($line eq ":0200000490303A") + { + my $checksumRec = sprintf(":02000000%04X", ($sum & 0xffff)); + + # create checksum of checksum record. + my $sum2 = unpack('%8C*', pack('H*', substr($checksumRec, 1))); + $checksumRec .= sprintf('%2X', (~$sum2 + 1) & 0xFF); + print("Flash data checksum record = $checksumRec\n"); + print("(Replace line below ':0200000490303A'\n"); + exit; + } + +} -- 2.38.5