]> cvs.zerfleddert.de Git - rsbs2/blame - firmware.c
use a struct for the property fields
[rsbs2] / firmware.c
CommitLineData
972ac24b
MG
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>
7f88d2b6 8#include <string.h>
972ac24b
MG
9#include <strings.h>
10#include "rsb-crc.h"
11
7f88d2b6
MG
12#define FINDSTR(addr, str) (!strncmp((char*)addr, str, strlen(str)))
13
39601b0e
MG
14struct properties {
15 unsigned int magic;
16 unsigned char unknown0;
17 unsigned char unknown1;
18 unsigned char right_rw;
19 unsigned char rw_mask;
20 unsigned char type1;
21 unsigned char unknown5;
22 unsigned char unknown6;
23 unsigned char unknown7;
24 unsigned char type2;
25 unsigned char val[];
26};
27
28void show_properties(unsigned char *fw, int len)
7f88d2b6
MG
29{
30 int i;
31
32 for (i = 0; i < (len-100 /* XXX */); i++) {
33 if (FINDSTR(fw+i, "/default/fw_prop/") ||
34 FINDSTR(fw+i, "/default/fw_setup/") ||
35 FINDSTR(fw+i, "/default/oem_prop/")) {
39601b0e 36 struct properties *prop;
7f88d2b6 37 unsigned char *pos = fw + i;
7f88d2b6
MG
38
39 printf("0x%08x: found setting: %s: ", i, pos);
7f88d2b6 40
39601b0e
MG
41 prop = (struct properties*)(pos + strlen((char*)pos) + 1);
42
43 if (prop->magic != 0x83011111) {
7f88d2b6
MG
44 printf("ignoring...\n");
45 continue;
46 }
47
39601b0e
MG
48 if (prop->type1 == 0x00 && prop->type2 == 0x04) {
49 printf("STRING: %s ", prop->val);
50 } else if (prop->type1 == 0x01 && prop->type2 == 0x01) {
51 printf("BOOL: %s ",(*prop->val ? "TRUE" : "FALSE"));
52 } else if (prop->type1 == 0x04 && prop->type2 == 0x02) {
53 printf("VAL: 0x%x ", *((unsigned int*)prop->val));
7f88d2b6 54 } else {
39601b0e 55 printf("0x%02x 0x%2x...ignoring\n", prop->type1, prop->type2);
7f88d2b6
MG
56 continue;
57 }
58
39601b0e 59 if (prop->right_rw == 0x00 && prop->rw_mask == 0x00) {
7f88d2b6 60 printf("(R-) ");
39601b0e
MG
61 } else if (prop->right_rw == 0x01) {
62 printf("(RW mask: 0x%02x) ", prop->rw_mask);
7f88d2b6 63 } else {
39601b0e 64 printf("(UNK 0x%02x 0x%02x) ", prop->right_rw, prop->rw_mask);
7f88d2b6
MG
65 }
66 printf("\n");
67 }
68 }
69}
70
71void handle_boarddescription(unsigned char *fw, int len, int patch)
72{
73 /* 0x01 0x01 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x88 0x02 0xac 0x01 0xd0 0x05 0x00 0x00 0x6a 0x3a 0x00 0x00 0x06 0x00 0x01 0x00 0x00 0x00 0x00 0x00 */
74}
75
972ac24b
MG
76int main(int argc, char **argv)
77{
78 struct stat statbuf;
79 unsigned char *fw;
80 int fd;
81 int remaining;
82 int ret;
6fc57dcd 83 unsigned int crc, oldcrc;
972ac24b
MG
84
85 if (argc != 2) {
86 fprintf(stderr,"Syntax: %s firmware.bin\n", argv[0]);
87 exit(1);
88 }
89
90 if (stat(argv[1], &statbuf) == -1) {
91 perror("stat");
92 exit(1);
93 }
94
95 if ((fd = open(argv[1], O_RDONLY)) == -1) {
96 perror("open");
97 exit(1);
98 }
99
100 if ((fw = malloc(statbuf.st_size)) == NULL) {
101 perror("malloc");
102 exit(1);
103 }
104
105 bzero(fw, statbuf.st_size);
106
107 remaining = statbuf.st_size;
108
109 while(remaining) {
110 if ((ret = read(fd, fw + (statbuf.st_size - remaining), remaining)) == -1) {
111 perror("read");
112 exit(1);
113 }
114 remaining -= ret;
115 }
116
6fc57dcd
MG
117 ret = rsb_crc2(fw, statbuf.st_size, 0x55335053, &crc);
118 oldcrc = (unsigned int)*((unsigned int*)(fw + statbuf.st_size - 4));
972ac24b 119
7c86ed4a
MG
120 printf("Checksum: 0x%08x (%s), should be: 0x%08x\n",
121 crc,
122 (ret ? "NOT OK" : "OK"),
123 oldcrc);
7f88d2b6
MG
124
125 if (1) {
39601b0e 126 show_properties(fw, statbuf.st_size - 4);
7f88d2b6
MG
127 handle_boarddescription(fw, statbuf.st_size - 4, 0);
128 if (0) {
129 ret = rsb_crc2(fw, statbuf.st_size, 0x55335053, &crc);
130 printf("Checksum: 0x%08x\n", crc);
131 }
132 }
972ac24b
MG
133
134 exit(0);
135}
Impressum, Datenschutz