Magellan Linux

Contents of /trunk/linterm_tools/fw_builder/bundle-tools/fwcs.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 658 - (show annotations) (download)
Mon Jan 14 16:57:24 2008 UTC (16 years, 3 months ago) by niro
File MIME type: text/plain
File size: 1513 byte(s)
initial import

1 /*
2 A small tool to calculate Wyse WinTerm firmware image checksums
3 Copyright (C) 2005 Wilmer van der Gaast <wilmer@gaast.net>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the second version of the GNU
7 General Public License as published by the Free Software
8 Foundation.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <stdio.h>
25
26 #if BYTE_ORDER == BIG_ENDIAN
27 #define cvt32(x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | (((x)&0xff0000)>>8) | (((x)&0xff000000)>>24))
28 #else
29 #define cvt32(x) (x)
30 #endif
31
32 int main( int argc, char *argv[] )
33 {
34 unsigned int checksum = 0xFFFE1000;
35 unsigned int tmp;
36 int fd;
37
38 if( argc < 2 )
39 {
40 fprintf( stderr, "Invalid number of arguments!\n" );
41 return( 1 );
42 }
43
44 fd = open( argv[1], O_RDONLY );
45 if( fd < 0 )
46 {
47 perror( "open" );
48 return( 1 );
49 }
50
51 while( read( fd, &tmp, 4 ) > 0 )
52 {
53 checksum -= cvt32( tmp );
54 tmp = 0;
55 }
56
57 printf( "%08x\n", checksum );
58
59 return( 0 );
60 }