]> git.zerfleddert.de Git - rsbs2/blob - firmware.c
7e5e112018e5c8d05c560f16deeb3372a45d0e99
[rsbs2] / firmware.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <unistd.h>
7 #include <errno.h>
8 #include <strings.h>
9 #include "rsb-crc.h"
10
11 int main(int argc, char **argv)
12 {
13 struct stat statbuf;
14 unsigned char *fw;
15 int fd;
16 int remaining;
17 int ret;
18 unsigned int crc, oldcrc;
19
20 if (argc != 2) {
21 fprintf(stderr,"Syntax: %s firmware.bin\n", argv[0]);
22 exit(1);
23 }
24
25 if (stat(argv[1], &statbuf) == -1) {
26 perror("stat");
27 exit(1);
28 }
29
30 if ((fd = open(argv[1], O_RDONLY)) == -1) {
31 perror("open");
32 exit(1);
33 }
34
35 if ((fw = malloc(statbuf.st_size)) == NULL) {
36 perror("malloc");
37 exit(1);
38 }
39
40 bzero(fw, statbuf.st_size);
41
42 remaining = statbuf.st_size;
43
44 while(remaining) {
45 if ((ret = read(fd, fw + (statbuf.st_size - remaining), remaining)) == -1) {
46 perror("read");
47 exit(1);
48 }
49 remaining -= ret;
50 }
51
52 ret = rsb_crc2(fw, statbuf.st_size, 0x55335053, &crc);
53 oldcrc = (unsigned int)*((unsigned int*)(fw + statbuf.st_size - 4));
54
55 printf("Checksum: 0x%08x (%s), should be: 0x%08x\n",
56 crc,
57 (ret ? "NOT OK" : "OK"),
58 oldcrc);
59
60 exit(0);
61 }
Impressum, Datenschutz