]>
git.zerfleddert.de Git - rsbs2/blob - firmware.c
6b47e2bf2c32b670107180ee4303377f9b229c9a
12 #define FINDSTR(addr, str) (!strncmp((char*)addr, str, strlen(str)))
16 unsigned char unknown0
;
17 unsigned char unknown1
;
18 unsigned char right_rw
;
19 unsigned char rw_mask
;
21 unsigned char unknown5
;
22 unsigned char unknown6
;
23 unsigned char unknown7
;
28 #define PROP_ACTION_TRUE (1<<0)
29 #define PROP_ACTION_FALSE (1<<1)
30 #define PROP_ACTION_RO (1<<2)
31 #define PROP_ACTION_RW (1<<3)
33 #define PROP_STATUS_NOTFOUND (0)
34 #define PROP_STATUS_WRONGTYPE (1<<0)
35 #define PROP_STATUS_WRONGRIGHTS (1<<1)
36 #define PROP_STATUS_SAMEVAL (1<<2)
37 #define PROP_STATUS_SUCCESS (1<<3)
43 struct propaction
*next
;
46 void show_properties(unsigned char *fw
, int len
)
50 for (i
= 0; i
< (len
-100 /* XXX */); i
++) {
51 if (FINDSTR(fw
+i
, "/default/fw_prop/") ||
52 FINDSTR(fw
+i
, "/default/fw_setup/") ||
53 FINDSTR(fw
+i
, "/default/oem_prop/")) {
54 struct properties
*prop
;
55 unsigned char *pos
= fw
+ i
;
57 printf("0x%08x: found setting: %s ", i
, pos
);
59 prop
= (struct properties
*)(pos
+ strlen((char*)pos
) + 1);
61 if (prop
->magic
!= 0x83011111) {
62 printf("ignoring...\n");
66 if (prop
->type1
== 0x00 && prop
->type2
== 0x04) {
67 printf("STRING: '%s' ", prop
->val
);
68 } else if (prop
->type1
== 0x01 && prop
->type2
== 0x01) {
69 printf("BOOL: %s ",(*prop
->val
? "TRUE" : "FALSE"));
70 } else if (prop
->type1
== 0x04 && prop
->type2
== 0x02) {
71 printf("VAL: 0x%x ", *((unsigned int*)prop
->val
));
73 printf("0x%02x 0x%2x...ignoring\n", prop
->type1
, prop
->type2
);
77 if (prop
->right_rw
== 0x00 && prop
->rw_mask
== 0x00) {
79 } else if (prop
->right_rw
== 0x01) {
80 printf("(RW mask: 0x%02x) ", prop
->rw_mask
);
82 printf("(UNK 0x%02x 0x%02x) ", prop
->right_rw
, prop
->rw_mask
);
89 void change_properties(unsigned char *fw
, int len
, struct propaction
*paction
)
92 struct propaction
*cpaction
;
94 for (i
= 0; i
< (len
-100 /* XXX */); i
++) {
96 while (cpaction
!= NULL
) {
97 if (FINDSTR(fw
+ i
, cpaction
->property
)) {
100 cpaction
= cpaction
->next
;
102 if (cpaction
!= NULL
) {
103 struct properties
*prop
;
104 unsigned char *pos
= fw
+ i
;
106 prop
= (struct properties
*)(pos
+ strlen((char*)pos
) + 1);
108 if (prop
->magic
!= 0x83011111) {
112 if (cpaction
->action
& (PROP_ACTION_TRUE
|PROP_ACTION_FALSE
)) {
113 if (prop
->type1
== 0x01 && prop
->type2
== 0x01) {
114 if (cpaction
->action
& PROP_ACTION_TRUE
) {
115 if (*prop
->val
== 0x00) {
117 cpaction
->status
|= PROP_STATUS_SUCCESS
;
119 cpaction
->status
|= PROP_STATUS_SAMEVAL
;
122 if (*prop
->val
== 0x01) {
124 cpaction
->status
|= PROP_STATUS_SUCCESS
;
126 cpaction
->status
|= PROP_STATUS_SAMEVAL
;
130 cpaction
->status
= PROP_STATUS_WRONGTYPE
;
133 if (cpaction
->action
& PROP_ACTION_RW
) {
134 if (prop
->right_rw
== 0x00 && prop
->rw_mask
== 0x00) {
135 prop
->right_rw
= 0x01;
136 prop
->rw_mask
= 0x02;
137 cpaction
->status
|= PROP_STATUS_SUCCESS
;
139 cpaction
->status
|= PROP_STATUS_WRONGRIGHTS
;
142 if (cpaction
->action
& PROP_ACTION_RO
) {
143 if (prop
->right_rw
== 0x01 && prop
->rw_mask
== 0x02) {
144 prop
->right_rw
= 0x00;
145 prop
->rw_mask
= 0x00;
146 cpaction
->status
|= PROP_STATUS_SUCCESS
;
148 cpaction
->status
|= PROP_STATUS_WRONGRIGHTS
;
155 void handle_boarddescription(unsigned char *fw
, int len
, int patch
)
157 /* 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 */
160 void syntax(char *name
)
162 fprintf(stderr
,"Syntax: %s parameters firmware.bin\n", name
);
163 fprintf(stderr
,"parameters as follows:\n");
164 fprintf(stderr
,"\t-d\t\tdisplay all properties of the image\n");
165 fprintf(stderr
,"\t-u\t\tupdate checksum of the image\n");
166 fprintf(stderr
,"\t-t property\tset 'property' to true\n");
167 fprintf(stderr
,"\t-f property\tset 'property' to false\n");
168 fprintf(stderr
,"\t-w property\tallow read-write access to 'property'\n");
169 fprintf(stderr
,"\t-r property\tallow read-only access to 'property'\n");
173 void add_action(int opt
, char *optarg
, struct propaction
**paction
) {
174 struct propaction
*pos
= *paction
;
175 struct propaction
*prev
= NULL
;
177 while (pos
!= NULL
) {
178 if (!strcmp(pos
->property
, optarg
))
185 pos
= malloc(sizeof(struct propaction
));
190 bzero(pos
, sizeof(struct propaction
));
191 pos
->property
= optarg
;
202 if (pos
->action
& PROP_ACTION_FALSE
) {
203 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
206 pos
->action
|= PROP_ACTION_TRUE
;
209 if (pos
->action
& PROP_ACTION_TRUE
) {
210 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
213 pos
->action
|= PROP_ACTION_FALSE
;
216 if (pos
->action
& PROP_ACTION_RO
) {
217 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
220 pos
->action
|= PROP_ACTION_RW
;
223 if (pos
->action
& PROP_ACTION_RW
) {
224 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
227 pos
->action
|= PROP_ACTION_RO
;
232 int check_crc(unsigned char *fw
, int len
)
235 unsigned int crc
, oldcrc
;
237 ret
= rsb_crc2(fw
, len
, 0x55335053, &crc
);
238 oldcrc
= (unsigned int)*((unsigned int*)(fw
+ len
- 4));
240 printf("Checksum: 0x%08x (%s), should be: 0x%08x\n",
242 (ret
? "NOT OK" : "OK"),
248 int main(int argc
, char **argv
)
258 struct propaction
*paction
= NULL
;
266 while ((opt
= getopt(argc
, argv
, "dut:f:w:r:")) != -1) {
279 add_action(opt
, optarg
, &paction
);
292 if (stat(file
, &statbuf
) == -1) {
293 fprintf(stderr
,"%s: ", file
);
298 if ((fd
= open(file
, O_RDONLY
)) == -1) {
299 fprintf(stderr
,"%s: ", file
);
304 if ((fw
= malloc(statbuf
.st_size
)) == NULL
) {
309 bzero(fw
, statbuf
.st_size
);
311 remaining
= statbuf
.st_size
;
314 if ((ret
= read(fd
, fw
+ (statbuf
.st_size
- remaining
), remaining
)) == -1) {
322 ret
= check_crc(fw
, statbuf
.st_size
);
323 if ((ret
!= 0) && (!update_crc
)) {
324 fprintf(stderr
,"Checksum incorrect, aborting...\n");
328 struct propaction
*cpaction
= paction
;
330 change_properties(fw
, statbuf
.st_size
, paction
);
332 printf("\nProperty change results:\n");
333 while(cpaction
!= NULL
) {
334 printf("%s: ", cpaction
->property
);
336 if (cpaction
->status
== PROP_STATUS_NOTFOUND
)
338 if (cpaction
->status
& PROP_STATUS_SUCCESS
)
340 if (cpaction
->status
& PROP_STATUS_SAMEVAL
)
342 if (cpaction
->status
& PROP_STATUS_WRONGTYPE
)
343 printf("WRONGTYPE ");
344 if (cpaction
->status
& PROP_STATUS_WRONGRIGHTS
)
345 printf("WRONGRIGHTS ");
348 cpaction
= cpaction
->next
;
354 show_properties(fw
, statbuf
.st_size
- 4);
356 if (update_crc
|| patch_fw
) {
357 ret
= rsb_crc2(fw
, statbuf
.st_size
, 0x55335053, &crc
);
359 *((unsigned int*)(fw
+ statbuf
.st_size
- 4)) = crc
;
362 if (check_crc(fw
, statbuf
.st_size
) == 0) {
365 newfile
= malloc(strlen(file
) + strlen(".patched") + 1);
366 if (newfile
== NULL
) {
370 strcpy(newfile
, file
);
371 strcat(newfile
, ".patched");
373 printf("Writing %s\n", newfile
);
374 if ((fd
= open(newfile
, O_WRONLY
|O_CREAT
, 0644)) == -1) {
375 fprintf(stderr
,"%s: ", file
);
380 remaining
= statbuf
.st_size
;
383 if ((ret
= write(fd
, fw
+ (statbuf
.st_size
- remaining
), remaining
)) == -1) {
391 fprintf(stderr
,"Can't set correct checksum, aborting...\n");