source: xtideuniversalbios/trunk/Tools/checksum.pl@ 346

Last change on this file since 346 was 203, checked in by gregli@…, 13 years ago

Reworked the 'skip detecting the slave if there was no master' code to be more complete (includes configurator drives) and to take into account int13h/25h calls. Some of the changes in my last checkin have been rolled back as a result (they are no longer needed). I did take a byte out of RAMVARS, but there was an alignment byte available for the taking. I also added a perl script for padding and adding the checksum byte to a binary image, which can be invoked manually or with 'make checksum'.

File size: 1.3 KB
RevLine 
[203]1@rem = '--*-Perl-*--
2@echo off
3perl -x -S %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
4goto endofperl
5@rem ';
6#!perl
7#
8# Add checksum byte to ROM image
9#
10# Use a size of 0 to skip this script entirely (file is not modified)
11#
12# On Windows, this file can be renamed to a batch file and invoked directly (for example, "c:\>checksum file size")
13#
14
15($ARGV[0] ne "" && $ARGV[1] ne "") || die "usage: checksum filename size\n";
16
17$desiredSize = int($ARGV[1]);
18
19if( $desiredSize == 0 )
20{
21 exit( 0 );
22}
23
24open FILE, "+<".$ARGV[0] || die "file not found\n";
25binmode FILE;
26$cs = 0;
27$last = 0;
28$bytes = 0;
29while( ($n = read( FILE, $d, 1 )) != 0 )
30{
31 $cs = $cs + ord($d);
32 $cs = $cs % 256;
33 $bytes = $bytes + 1;
34}
35$oldBytes = $bytes;
36
37if( $bytes > $desiredSize - 1 )
38{
39 die "ERROR: image is bigger than ".($desiredSize-1).": $bytes\n";
40}
41
42$fixzero = chr(0);
43while( $bytes < $desiredSize - 1 )
44{
45 print FILE $fixzero;
46 $bytes++;
47}
48
49$fixl = ($cs == 0 ? 0 : 256 - $cs);
50$fix = chr($fixl);
51print FILE $fix;
52
53close FILE;
54
55open FILE, "<".$ARGV[0];
56binmode FILE;
57$cs = 0;
58$newBytes = 0;
59while( ($n = read( FILE, $d, 1 )) != 0 )
60{
61 $cs = $cs + ord($d);
62 $cs = $cs % 256;
63 $newBytes++;
64}
65$cs == 0 || die "Checksum verification failed\n";
66
67print "checksum: ".$ARGV[0].": $oldBytes bytes before, $newBytes bytes after\n";
68
69__DATA__
70:endofperl
Note: See TracBrowser for help on using the repository browser.