]>
git.zerfleddert.de Git - rsbs2/blob - firmware.c
cd7927b8f9854d86c20696adcfaabd8285f18dbf
13 #define FINDSTR(addr, str) (!strncmp((char*)addr, str, strlen(str)))
17 unsigned char unknown0
;
18 unsigned char unknown1
;
19 unsigned char right_rw
;
20 unsigned char rw_mask
;
22 unsigned char unknown5
;
23 unsigned char unknown6
;
24 unsigned char unknown7
;
29 #define PROP_ACTION_TRUE (1<<0)
30 #define PROP_ACTION_FALSE (1<<1)
31 #define PROP_ACTION_RO (1<<2)
32 #define PROP_ACTION_RW (1<<3)
34 #define PROP_STATUS_NOTFOUND (0)
35 #define PROP_STATUS_WRONGTYPE (1<<0)
36 #define PROP_STATUS_WRONGRIGHTS (1<<1)
37 #define PROP_STATUS_SAMEVAL (1<<2)
38 #define PROP_STATUS_SUCCESS (1<<3)
44 struct propaction
*next
;
47 void show_properties(unsigned char *fw
, int len
)
51 for (i
= 0; i
< (len
-100 /* XXX */); i
++) {
52 if (FINDSTR(fw
+i
, "/default/fw_prop/") ||
53 FINDSTR(fw
+i
, "/default/fw_setup/") ||
54 FINDSTR(fw
+i
, "/default/oem_prop/")) {
55 struct properties
*prop
;
56 unsigned char *pos
= fw
+ i
;
58 printf("0x%08x: found setting: %s ", i
, pos
);
60 prop
= (struct properties
*)(pos
+ strlen((char*)pos
) + 1);
62 if (prop
->magic
!= 0x83011111) {
63 printf("ignoring...\n");
67 if (prop
->type1
== 0x00 && prop
->type2
== 0x04) {
68 printf("STRING: '%s' ", prop
->val
);
69 } else if (prop
->type1
== 0x01 && prop
->type2
== 0x01) {
70 printf("BOOL: %s ",(*prop
->val
? "TRUE" : "FALSE"));
71 } else if (prop
->type1
== 0x04 && prop
->type2
== 0x02) {
72 printf("VAL: 0x%x ", *((unsigned int*)prop
->val
));
74 printf("0x%02x 0x%2x...ignoring\n", prop
->type1
, prop
->type2
);
78 if (prop
->right_rw
== 0x00 && prop
->rw_mask
== 0x00) {
80 } else if (prop
->right_rw
== 0x01) {
81 printf("(RW mask: 0x%02x)", prop
->rw_mask
);
83 printf("(UNK 0x%02x 0x%02x)", prop
->right_rw
, prop
->rw_mask
);
85 printf(", length: %d\n", *((unsigned int*)(fw
+ i
- 4)));
90 void change_properties(unsigned char *fw
, int len
, struct propaction
*paction
)
93 struct propaction
*cpaction
;
95 for (i
= 0; i
< (len
-100 /* XXX */); i
++) {
97 while (cpaction
!= NULL
) {
98 if (FINDSTR(fw
+ i
, cpaction
->property
)) {
101 cpaction
= cpaction
->next
;
103 if (cpaction
!= NULL
) {
104 struct properties
*prop
;
105 unsigned char *pos
= fw
+ i
;
107 prop
= (struct properties
*)(pos
+ strlen((char*)pos
) + 1);
109 if (prop
->magic
!= 0x83011111) {
113 if (cpaction
->action
& (PROP_ACTION_TRUE
|PROP_ACTION_FALSE
)) {
114 if (prop
->type1
== 0x01 && prop
->type2
== 0x01) {
115 if (cpaction
->action
& PROP_ACTION_TRUE
) {
116 if (*prop
->val
== 0x00) {
118 cpaction
->status
|= PROP_STATUS_SUCCESS
;
120 cpaction
->status
|= PROP_STATUS_SAMEVAL
;
123 if (*prop
->val
== 0x01) {
125 cpaction
->status
|= PROP_STATUS_SUCCESS
;
127 cpaction
->status
|= PROP_STATUS_SAMEVAL
;
131 cpaction
->status
= PROP_STATUS_WRONGTYPE
;
134 if (cpaction
->action
& PROP_ACTION_RW
) {
135 if (prop
->right_rw
== 0x00 && prop
->rw_mask
== 0x00) {
136 prop
->right_rw
= 0x01;
137 prop
->rw_mask
= 0x02;
138 cpaction
->status
|= PROP_STATUS_SUCCESS
;
140 cpaction
->status
|= PROP_STATUS_WRONGRIGHTS
;
143 if (cpaction
->action
& PROP_ACTION_RO
) {
144 if (prop
->right_rw
== 0x01 && prop
->rw_mask
== 0x02) {
145 prop
->right_rw
= 0x00;
146 prop
->rw_mask
= 0x00;
147 cpaction
->status
|= PROP_STATUS_SUCCESS
;
149 cpaction
->status
|= PROP_STATUS_WRONGRIGHTS
;
156 #define BD_SERIAL1 0x14,0x02
157 #define BD_ICMB 0x14,0x04
158 #define BD_LAN 0x14,0x08
159 #define BD_SERIAL2 0x14,0x10
160 #define BD_SERIAL3 0x14,0x20
161 #define BD_USB 0x14,0x40
162 #define BD_PCI 0x15,0x03
163 #define BD_LPC 0x15,0x04
164 #define BD_VGA 0x15,0x08
165 #define BD_BATTERY 0x15,0x10
166 #define BD_ACDC 0x15,0x20
167 #define BD_STANDBY 0x15,0x40
168 #define BD_POWERCONN 0x15,0x70
169 #define BD_DVI 0x15,0x80
170 #define BD_PWRATX 0x16,0x01
171 #define BD_PWRRELAY 0x16,0x02
172 #define BD_PS2A 0x19,0xff
174 #define MAGIC(fn, args...) fn(args)
176 #define _BD_IS_SET(bd, byte, bits) (bd[byte] & bits)
177 #define BD_IS_SET(bd, ident) MAGIC(_BD_IS_SET, bd, BD_##ident)
178 #define BD_TEXT(bd, ident) (BD_IS_SET(bd, ident) ? "TRUE" : "FALSE")
180 #define _BD_SET(bd, byte, bits) (bd[byte] |= bits)
181 #define BD_SET(bd, ident) MAGIC(_BD_SET, bd, BD_##ident)
183 void print_boarddescription(unsigned char *bd
)
187 for (j
= 0; j
< 32; j
++) {
188 printf("%02x ", *(bd
+j
));
192 /* com/agilent/rmc/amr/AmrMaster.class
193 * com/agilent/rmc/mgui/RmcPanel.class
194 * com/agilent/rmc/mgui/panels/AvrManualConfig.class
195 * com/agilent/rmc/mgui/panels/CardConf.jad
196 * com/agilent/rmc/mgui/panels/PowerMgmtConf.jad
197 * com/agilent/rmc/mgui/panels/RemoteDiskConf.jad
199 printf("\tserial1Present\t\t: %s\n", BD_TEXT(bd
, SERIAL1
));
200 printf("\ticmbPresent\t\t: %s\n", BD_TEXT(bd
, ICMB
));
201 printf("\tlanPresent\t\t: %s\n", BD_TEXT(bd
, LAN
));
202 printf("\tserial2Present\t\t: %s\n", BD_TEXT(bd
, SERIAL2
));
203 printf("\tserial3Present\t\t: %s\n", BD_TEXT(bd
, SERIAL3
));
204 printf("\tusbPresent\t\t: %s\n", BD_TEXT(bd
, USB
));
205 printf("\tpciPresent\t\t: %s\n", BD_TEXT(bd
, PCI
));
206 printf("\tlpcPresent\t\t: %s\n", BD_TEXT(bd
, LPC
));
207 printf("\tvgaPresent\t\t: %s\n", BD_TEXT(bd
, VGA
));
208 printf("\tbatteryPresent\t\t: %s\n", BD_TEXT(bd
, BATTERY
));
209 printf("\tacdcPresent\t\t: %s\n", BD_TEXT(bd
, ACDC
));
210 printf("\tstandbyPresent\t\t: %s\n", BD_TEXT(bd
, STANDBY
));
211 printf("\thasPowerConnectors\t: %s\n", BD_TEXT(bd
, POWERCONN
));
212 printf("\tdviPresent\t\t: %s\n", BD_TEXT(bd
, DVI
));
213 printf("\tpowerSwitchATX\t\t: %s\n", BD_TEXT(bd
, PWRATX
));
214 printf("\tpowerSwitchRelay\t: %s\n", BD_TEXT(bd
, PWRRELAY
));
216 printf("\tps2aPresent\t\t: %s\n", BD_TEXT(bd
, PS2A
));
219 void handle_boarddescription(unsigned char *fw
, int len
, int patch
)
223 for (i
= len
- (strlen("pdata")+1); i
> 0; i
--) {
224 if (FINDSTR(fw
+i
, "pdata")) {
225 unsigned char *pos
= fw
+ i
+ strlen("pdata") + 1;
228 if (*((unsigned int*)pos
) != 0x00002802) {
235 if (*((unsigned int*)pos
) != 0x00500101) {
240 /* Enable relay power switching */
241 BD_SET(pos
, PWRRELAY
);
243 printf("0x%08x: BOARD_DESCRIPTION: ", pos
-fw
);
244 print_boarddescription(pos
);
251 void syntax(char *name
)
253 fprintf(stderr
,"Syntax: %s parameters firmware.bin\n", name
);
254 fprintf(stderr
,"parameters as follows:\n");
255 fprintf(stderr
,"\t-d\t\tdisplay all properties of the image\n");
256 fprintf(stderr
,"\t-u\t\tupdate checksum of the image\n");
257 fprintf(stderr
,"\t-b\t\tmodify BOARD_DESCRIPTION for more power-switch options\n");
258 fprintf(stderr
,"\t-e\t\textract files in firmware\n");
259 fprintf(stderr
,"\t-t property\tset 'property' to true\n");
260 fprintf(stderr
,"\t-f property\tset 'property' to false\n");
261 fprintf(stderr
,"\t-w property\tallow read-write access to 'property'\n");
262 fprintf(stderr
,"\t-r property\tallow read-only access to 'property'\n");
266 void add_action(int opt
, char *optarg
, struct propaction
**paction
) {
267 struct propaction
*pos
= *paction
;
268 struct propaction
*prev
= NULL
;
270 while (pos
!= NULL
) {
271 if (!strcmp(pos
->property
, optarg
))
278 pos
= malloc(sizeof(struct propaction
));
283 bzero(pos
, sizeof(struct propaction
));
284 pos
->property
= optarg
;
295 if (pos
->action
& PROP_ACTION_FALSE
) {
296 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
299 pos
->action
|= PROP_ACTION_TRUE
;
302 if (pos
->action
& PROP_ACTION_TRUE
) {
303 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
306 pos
->action
|= PROP_ACTION_FALSE
;
309 if (pos
->action
& PROP_ACTION_RO
) {
310 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
313 pos
->action
|= PROP_ACTION_RW
;
316 if (pos
->action
& PROP_ACTION_RW
) {
317 fprintf(stderr
,"inconsistent requests for %s\n",pos
->property
);
320 pos
->action
|= PROP_ACTION_RO
;
325 int check_crc(unsigned char *fw
, int len
)
328 unsigned int crc
, oldcrc
;
330 ret
= rsb_crc2(fw
, len
, 0x55335053, &crc
);
331 oldcrc
= (unsigned int)*((unsigned int*)(fw
+ len
- 4));
333 printf("Checksum: 0x%08x (%s), should be: 0x%08x\n",
335 (ret
? "NOT OK" : "OK"),
341 int main(int argc
, char **argv
)
351 struct propaction
*paction
= NULL
;
361 while ((opt
= getopt(argc
, argv
, "dubet:f:w:r:")) != -1) {
380 add_action(opt
, optarg
, &paction
);
393 if (stat(file
, &statbuf
) == -1) {
394 fprintf(stderr
,"%s: ", file
);
399 if ((fd
= open(file
, O_RDONLY
)) == -1) {
400 fprintf(stderr
,"%s: ", file
);
405 if ((fw
= malloc(statbuf
.st_size
)) == NULL
) {
410 bzero(fw
, statbuf
.st_size
);
412 remaining
= statbuf
.st_size
;
415 if ((ret
= read(fd
, fw
+ (statbuf
.st_size
- remaining
), remaining
)) == -1) {
423 ret
= check_crc(fw
, statbuf
.st_size
);
424 if ((ret
!= 0) && (!update_crc
)) {
425 fprintf(stderr
,"Checksum incorrect, aborting...\n");
430 struct propaction
*cpaction
= paction
;
432 change_properties(fw
, statbuf
.st_size
, paction
);
434 printf("\nProperty change results:\n");
435 while(cpaction
!= NULL
) {
436 printf("%s: ", cpaction
->property
);
438 if (cpaction
->status
== PROP_STATUS_NOTFOUND
)
440 if (cpaction
->status
& PROP_STATUS_SUCCESS
)
442 if (cpaction
->status
& PROP_STATUS_SAMEVAL
)
444 if (cpaction
->status
& PROP_STATUS_WRONGTYPE
)
445 printf("WRONGTYPE ");
446 if (cpaction
->status
& PROP_STATUS_WRONGRIGHTS
)
447 printf("WRONGRIGHTS ");
450 cpaction
= cpaction
->next
;
456 handle_boarddescription(fw
, statbuf
.st_size
-4, 1);
460 show_properties(fw
, statbuf
.st_size
- 4);
461 handle_boarddescription(fw
, statbuf
.st_size
-4, 0);
465 extract_files(fw
, statbuf
.st_size
- 4);
468 if (update_crc
|| patch_fw
|| patch_bd
) {
469 ret
= rsb_crc2(fw
, statbuf
.st_size
, 0x55335053, &crc
);
471 *((unsigned int*)(fw
+ statbuf
.st_size
- 4)) = crc
;
474 if (check_crc(fw
, statbuf
.st_size
) == 0) {
477 newfile
= malloc(strlen(file
) + strlen(".patched") + 1);
478 if (newfile
== NULL
) {
482 strcpy(newfile
, file
);
483 strcat(newfile
, ".patched");
485 printf("Writing %s\n", newfile
);
486 if ((fd
= open(newfile
, O_WRONLY
|O_CREAT
, 0644)) == -1) {
487 fprintf(stderr
,"%s: ", file
);
492 remaining
= statbuf
.st_size
;
495 if ((ret
= write(fd
, fw
+ (statbuf
.st_size
- remaining
), remaining
)) == -1) {
503 fprintf(stderr
,"Can't set correct checksum, aborting...\n");