]>
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 #define BD_SERIAL1 0x14,0x02
156 #define BD_ICMB 0x14,0x04
157 #define BD_LAN 0x14,0x08
158 #define BD_SERIAL2 0x14,0x10
159 #define BD_SERIAL3 0x14,0x20
160 #define BD_USB 0x14,0x40
161 #define BD_PCI 0x15,0x03
162 #define BD_LPC 0x15,0x04
163 #define BD_VGA 0x15,0x08
164 #define BD_BATTERY 0x15,0x10
165 #define BD_ACDC 0x15,0x20
166 #define BD_STANDBY 0x15,0x40
167 #define BD_POWERCONN 0x15,0x70
168 #define BD_DVI 0x15,0x80
169 #define BD_PWRATX 0x16,0x01
170 #define BD_PWRRELAY 0x16,0x02
171 #define BD_PS2A 0x19,0xff
173 #define MAGIC(fn, args...) fn(args)
175 #define _BD_IS_SET(bd, byte, bits) (bd[byte] & bits)
176 #define BD_IS_SET(bd, ident) MAGIC(_BD_IS_SET, bd, BD_##ident)
177 #define BD_TEXT(bd, ident) (BD_IS_SET(bd, ident) ? "TRUE" : "FALSE")
179 #define _BD_SET(bd, byte, bits) (bd[byte] |= bits)
180 #define BD_SET(bd, ident) MAGIC(_BD_SET, bd, BD_##ident)
182 void print_boarddescription(unsigned char *bd
)
186 for (j
= 0; j
< 32; j
++) {
187 printf("%02x ", *(bd
+j
));
191 /* com/agilent/rmc/amr/AmrMaster.class
192 * com/agilent/rmc/mgui/RmcPanel.class
193 * com/agilent/rmc/mgui/panels/AvrManualConfig.class
194 * com/agilent/rmc/mgui/panels/CardConf.jad
195 * com/agilent/rmc/mgui/panels/PowerMgmtConf.jad
196 * com/agilent/rmc/mgui/panels/RemoteDiskConf.jad
198 printf("\tserial1Present\t\t: %s\n", BD_TEXT(bd
, SERIAL1
));
199 printf("\ticmbPresent\t\t: %s\n", BD_TEXT(bd
, ICMB
));
200 printf("\tlanPresent\t\t: %s\n", BD_TEXT(bd
, LAN
));
201 printf("\tserial2Present\t\t: %s\n", BD_TEXT(bd
, SERIAL2
));
202 printf("\tserial3Present\t\t: %s\n", BD_TEXT(bd
, SERIAL3
));
203 printf("\tusbPresent\t\t: %s\n", BD_TEXT(bd
, USB
));
204 printf("\tpciPresent\t\t: %s\n", BD_TEXT(bd
, PCI
));
205 printf("\tlpcPresent\t\t: %s\n", BD_TEXT(bd
, LPC
));
206 printf("\tvgaPresent\t\t: %s\n", BD_TEXT(bd
, VGA
));
207 printf("\tbatteryPresent\t\t: %s\n", BD_TEXT(bd
, BATTERY
));
208 printf("\tacdcPresent\t\t: %s\n", BD_TEXT(bd
, ACDC
));
209 printf("\tstandbyPresent\t\t: %s\n", BD_TEXT(bd
, STANDBY
));
210 printf("\thasPowerConnectors\t: %s\n", BD_TEXT(bd
, POWERCONN
));
211 printf("\tdviPresent\t\t: %s\n", BD_TEXT(bd
, DVI
));
212 printf("\tpowerSwitchATX\t\t: %s\n", BD_TEXT(bd
, PWRATX
));
213 printf("\tpowerSwitchRelay\t: %s\n", BD_TEXT(bd
, PWRRELAY
));
215 printf("\tps2aPresent\t\t: %s\n", BD_TEXT(bd
, PS2A
));
218 void handle_boarddescription(unsigned char *fw
, int len
, int patch
)
222 for (i
= len
- (strlen("pdata")+1); i
> 0; i
--) {
223 if (FINDSTR(fw
+i
, "pdata")) {
224 unsigned char *pos
= fw
+ i
+ strlen("pdata") + 1;
227 if (*((unsigned int*)pos
) != 0x00002802) {
234 if (*((unsigned int*)pos
) != 0x00500101) {
239 /* Enable ATX and relay power switching */
241 BD_SET(pos
, PWRRELAY
);
243 BD_SET(pos
, STANDBY
);
245 printf("0x%08x: BOARD_DESCRIPTION: ", pos
-fw
);
246 print_boarddescription(pos
);
253 void syntax(char *name
)
255 fprintf(stderr
,"Syntax: %s parameters firmware.bin\n", name
);
256 fprintf(stderr
,"parameters as follows:\n");
257 fprintf(stderr
,"\t-d\t\tdisplay all properties of the image\n");
258 fprintf(stderr
,"\t-u\t\tupdate checksum of the image\n");
259 fprintf(stderr
,"\t-b\t\tmodify BOARD_DESCRIPTION for more power-switch options\n");
260 fprintf(stderr
,"\t-t property\tset 'property' to true\n");
261 fprintf(stderr
,"\t-f property\tset 'property' to false\n");
262 fprintf(stderr
,"\t-w property\tallow read-write access to 'property'\n");
263 fprintf(stderr
,"\t-r property\tallow read-only access to 'property'\n");
267 void add_action(int opt
, char *optarg
, struct propaction
**paction
) {
268 struct propaction
*pos
= *paction
;
269 struct propaction
*prev
= NULL
;
271 while (pos
!= NULL
) {
272 if (!strcmp(pos
->property
, optarg
))
279 pos
= malloc(sizeof(struct propaction
));
284 bzero(pos
, sizeof(struct propaction
));
285 pos
->property
= optarg
;
296 if (pos
->action
& PROP_ACTION_FALSE
) {
297 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
300 pos
->action
|= PROP_ACTION_TRUE
;
303 if (pos
->action
& PROP_ACTION_TRUE
) {
304 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
307 pos
->action
|= PROP_ACTION_FALSE
;
310 if (pos
->action
& PROP_ACTION_RO
) {
311 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
314 pos
->action
|= PROP_ACTION_RW
;
317 if (pos
->action
& PROP_ACTION_RW
) {
318 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
321 pos
->action
|= PROP_ACTION_RO
;
326 int check_crc(unsigned char *fw
, int len
)
329 unsigned int crc
, oldcrc
;
331 ret
= rsb_crc2(fw
, len
, 0x55335053, &crc
);
332 oldcrc
= (unsigned int)*((unsigned int*)(fw
+ len
- 4));
334 printf("Checksum: 0x%08x (%s), should be: 0x%08x\n",
336 (ret
? "NOT OK" : "OK"),
342 int main(int argc
, char **argv
)
352 struct propaction
*paction
= NULL
;
361 while ((opt
= getopt(argc
, argv
, "dubt:f:w:r:")) != -1) {
377 add_action(opt
, optarg
, &paction
);
390 if (stat(file
, &statbuf
) == -1) {
391 fprintf(stderr
,"%s: ", file
);
396 if ((fd
= open(file
, O_RDONLY
)) == -1) {
397 fprintf(stderr
,"%s: ", file
);
402 if ((fw
= malloc(statbuf
.st_size
)) == NULL
) {
407 bzero(fw
, statbuf
.st_size
);
409 remaining
= statbuf
.st_size
;
412 if ((ret
= read(fd
, fw
+ (statbuf
.st_size
- remaining
), remaining
)) == -1) {
420 ret
= check_crc(fw
, statbuf
.st_size
);
421 if ((ret
!= 0) && (!update_crc
)) {
422 fprintf(stderr
,"Checksum incorrect, aborting...\n");
426 struct propaction
*cpaction
= paction
;
428 change_properties(fw
, statbuf
.st_size
, paction
);
430 printf("\nProperty change results:\n");
431 while(cpaction
!= NULL
) {
432 printf("%s: ", cpaction
->property
);
434 if (cpaction
->status
== PROP_STATUS_NOTFOUND
)
436 if (cpaction
->status
& PROP_STATUS_SUCCESS
)
438 if (cpaction
->status
& PROP_STATUS_SAMEVAL
)
440 if (cpaction
->status
& PROP_STATUS_WRONGTYPE
)
441 printf("WRONGTYPE ");
442 if (cpaction
->status
& PROP_STATUS_WRONGRIGHTS
)
443 printf("WRONGRIGHTS ");
446 cpaction
= cpaction
->next
;
452 handle_boarddescription(fw
, statbuf
.st_size
-4, 1);
456 show_properties(fw
, statbuf
.st_size
- 4);
457 handle_boarddescription(fw
, statbuf
.st_size
-4, 0);
460 if (update_crc
|| patch_fw
|| patch_bd
) {
461 ret
= rsb_crc2(fw
, statbuf
.st_size
, 0x55335053, &crc
);
463 *((unsigned int*)(fw
+ statbuf
.st_size
- 4)) = crc
;
466 if (check_crc(fw
, statbuf
.st_size
) == 0) {
469 newfile
= malloc(strlen(file
) + strlen(".patched") + 1);
470 if (newfile
== NULL
) {
474 strcpy(newfile
, file
);
475 strcat(newfile
, ".patched");
477 printf("Writing %s\n", newfile
);
478 if ((fd
= open(newfile
, O_WRONLY
|O_CREAT
, 0644)) == -1) {
479 fprintf(stderr
,"%s: ", file
);
484 remaining
= statbuf
.st_size
;
487 if ((ret
= write(fd
, fw
+ (statbuf
.st_size
- remaining
), remaining
)) == -1) {
495 fprintf(stderr
,"Can't set correct checksum, aborting...\n");