]>
cvs.zerfleddert.de Git - rsbs2/blob - firmware.c
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 print_boarddescription(unsigned char *bd
)
159 for (j
= 0; j
< 32; j
++) {
160 printf("%02x ", *(bd
+j
));
164 /* com/agilent/rmc/amr/AmrMaster.class
165 * com/agilent/rmc/mgui/RmcPanel.class
166 * com/agilent/rmc/mgui/panels/AvrManualConfig.class
167 * com/agilent/rmc/mgui/panels/CardConf.jad
168 * com/agilent/rmc/mgui/panels/PowerMgmtConf.jad
169 * com/agilent/rmc/mgui/panels/RemoteDiskConf.jad
171 printf("\tserial1Present\t\t: %s\n", ((bd
[20] & 2) ? "TRUE" : "FALSE"));
172 printf("\ticmbPresent\t\t: %s\n", ((bd
[20] & 4) ? "TRUE" : "FALSE"));
173 printf("\tlanPresent\t\t: %s\n", ((bd
[20] & 8) ? "TRUE" : "FALSE"));
174 printf("\tserial2Present\t\t: %s\n", ((bd
[20] & 0x10) ? "TRUE" : "FALSE"));
175 printf("\tserial3Present\t\t: %s\n", ((bd
[20] & 0x20) ? "TRUE" : "FALSE"));
176 printf("\tusbPresent\t\t: %s\n", ((bd
[20] & 0x40) ? "TRUE" : "FALSE"));
177 printf("\tpciPresent\t\t: %s\n", ((bd
[21] & 3) ? "TRUE" : "FALSE"));
178 printf("\tlpcPresent\t\t: %s\n", ((bd
[21] & 4) ? "TRUE" : "FALSE"));
179 printf("\tvgaPresent\t\t: %s\n", ((bd
[21] & 8) ? "TRUE" : "FALSE"));
180 printf("\tbatteryPresent\t\t: %s\n", ((bd
[21] & 0x10) ? "TRUE" : "FALSE"));
181 printf("\tacdcPresent\t\t: %s\n", ((bd
[21] & 0x20) ? "TRUE" : "FALSE"));
182 printf("\tstandbyPresent\t\t: %s\n", ((bd
[21] & 0x40) ? "TRUE" : "FALSE"));
183 printf("\thasPowerConnectors\t: %s\n", ((bd
[21] & 0x70) ? "TRUE" : "FALSE"));
184 printf("\tdviPresent\t\t: %s\n", ((bd
[21] & 0x80) ? "TRUE" : "FALSE"));
185 printf("\tpowerSwitchATX\t\t: %s\n", ((bd
[22] & 1) ? "TRUE" : "FALSE"));
186 printf("\tpowerSwitchRelay\t: %s\n", ((bd
[22] & 2) ? "TRUE" : "FALSE"));
188 printf("\tps2aPresent\t\t: %s\n", ((bd
[25]) ? "TRUE" : "FALSE"));
191 void handle_boarddescription(unsigned char *fw
, int len
, int patch
)
195 for (i
= len
- (strlen("pdata")+1); i
> 0; i
--) {
196 if (FINDSTR(fw
+i
, "pdata")) {
197 unsigned char *pos
= fw
+ i
+ strlen("pdata") + 1;
200 if (*((unsigned int*)pos
) != 0x00002802) {
207 if (*((unsigned int*)pos
) != 0x00500101) {
212 /* Enable ATX and relay power switching */
215 printf("0x%08x: BOARD_DESCRIPTION: ", pos
-fw
);
216 print_boarddescription(pos
);
223 void syntax(char *name
)
225 fprintf(stderr
,"Syntax: %s parameters firmware.bin\n", name
);
226 fprintf(stderr
,"parameters as follows:\n");
227 fprintf(stderr
,"\t-d\t\tdisplay all properties of the image\n");
228 fprintf(stderr
,"\t-u\t\tupdate checksum of the image\n");
229 fprintf(stderr
,"\t-b\t\tmodify BOARD_DESCRIPTION for more power-switch options\n");
230 fprintf(stderr
,"\t-t property\tset 'property' to true\n");
231 fprintf(stderr
,"\t-f property\tset 'property' to false\n");
232 fprintf(stderr
,"\t-w property\tallow read-write access to 'property'\n");
233 fprintf(stderr
,"\t-r property\tallow read-only access to 'property'\n");
237 void add_action(int opt
, char *optarg
, struct propaction
**paction
) {
238 struct propaction
*pos
= *paction
;
239 struct propaction
*prev
= NULL
;
241 while (pos
!= NULL
) {
242 if (!strcmp(pos
->property
, optarg
))
249 pos
= malloc(sizeof(struct propaction
));
254 bzero(pos
, sizeof(struct propaction
));
255 pos
->property
= optarg
;
266 if (pos
->action
& PROP_ACTION_FALSE
) {
267 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
270 pos
->action
|= PROP_ACTION_TRUE
;
273 if (pos
->action
& PROP_ACTION_TRUE
) {
274 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
277 pos
->action
|= PROP_ACTION_FALSE
;
280 if (pos
->action
& PROP_ACTION_RO
) {
281 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
284 pos
->action
|= PROP_ACTION_RW
;
287 if (pos
->action
& PROP_ACTION_RW
) {
288 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
291 pos
->action
|= PROP_ACTION_RO
;
296 int check_crc(unsigned char *fw
, int len
)
299 unsigned int crc
, oldcrc
;
301 ret
= rsb_crc2(fw
, len
, 0x55335053, &crc
);
302 oldcrc
= (unsigned int)*((unsigned int*)(fw
+ len
- 4));
304 printf("Checksum: 0x%08x (%s), should be: 0x%08x\n",
306 (ret
? "NOT OK" : "OK"),
312 int main(int argc
, char **argv
)
322 struct propaction
*paction
= NULL
;
331 while ((opt
= getopt(argc
, argv
, "dubt:f:w:r:")) != -1) {
347 add_action(opt
, optarg
, &paction
);
360 if (stat(file
, &statbuf
) == -1) {
361 fprintf(stderr
,"%s: ", file
);
366 if ((fd
= open(file
, O_RDONLY
)) == -1) {
367 fprintf(stderr
,"%s: ", file
);
372 if ((fw
= malloc(statbuf
.st_size
)) == NULL
) {
377 bzero(fw
, statbuf
.st_size
);
379 remaining
= statbuf
.st_size
;
382 if ((ret
= read(fd
, fw
+ (statbuf
.st_size
- remaining
), remaining
)) == -1) {
390 ret
= check_crc(fw
, statbuf
.st_size
);
391 if ((ret
!= 0) && (!update_crc
)) {
392 fprintf(stderr
,"Checksum incorrect, aborting...\n");
396 struct propaction
*cpaction
= paction
;
398 change_properties(fw
, statbuf
.st_size
, paction
);
400 printf("\nProperty change results:\n");
401 while(cpaction
!= NULL
) {
402 printf("%s: ", cpaction
->property
);
404 if (cpaction
->status
== PROP_STATUS_NOTFOUND
)
406 if (cpaction
->status
& PROP_STATUS_SUCCESS
)
408 if (cpaction
->status
& PROP_STATUS_SAMEVAL
)
410 if (cpaction
->status
& PROP_STATUS_WRONGTYPE
)
411 printf("WRONGTYPE ");
412 if (cpaction
->status
& PROP_STATUS_WRONGRIGHTS
)
413 printf("WRONGRIGHTS ");
416 cpaction
= cpaction
->next
;
422 handle_boarddescription(fw
, statbuf
.st_size
-4, 1);
426 show_properties(fw
, statbuf
.st_size
- 4);
427 handle_boarddescription(fw
, statbuf
.st_size
-4, 0);
430 if (update_crc
|| patch_fw
|| patch_bd
) {
431 ret
= rsb_crc2(fw
, statbuf
.st_size
, 0x55335053, &crc
);
433 *((unsigned int*)(fw
+ statbuf
.st_size
- 4)) = crc
;
436 if (check_crc(fw
, statbuf
.st_size
) == 0) {
439 newfile
= malloc(strlen(file
) + strlen(".patched") + 1);
440 if (newfile
== NULL
) {
444 strcpy(newfile
, file
);
445 strcat(newfile
, ".patched");
447 printf("Writing %s\n", newfile
);
448 if ((fd
= open(newfile
, O_WRONLY
|O_CREAT
, 0644)) == -1) {
449 fprintf(stderr
,"%s: ", file
);
454 remaining
= statbuf
.st_size
;
457 if ((ret
= write(fd
, fw
+ (statbuf
.st_size
- remaining
), remaining
)) == -1) {
465 fprintf(stderr
,"Can't set correct checksum, aborting...\n");