]> git.zerfleddert.de Git - rsbs2/blobdiff - firmware.c
decode settings in firmware
[rsbs2] / firmware.c
index f8584c163caa3ef4aa9aec3250dccc8e37d6cfe8..0361634b4131e1342c2bb7c740ccb4cc57def415 100644 (file)
@@ -5,39 +5,73 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
+#include <string.h>
 #include <strings.h>
 #include "rsb-crc.h"
 
-struct fw_header {
-       unsigned int unknown[8];
-       unsigned int len;
-       char ident[4];
-       unsigned int offset;
-       char desc[128];
-};
-
-void parse_fw(unsigned char *fw, unsigned int off) {
-       struct fw_header *header = (struct fw_header*)(fw + off);
-       static unsigned int last_off;
-       int i;
-
-       printf("Address in file: 0x%08x, Difference to last: %u\n", off, off-last_off);
-       printf("Unknown: ");
-       for (i = 0; i < 8; i++)
-               printf("0x%08x ", header->unknown[i]);
-
-       printf("\n");
-
-       printf("Length: %u, possible next entry at: 0x%08x\n", header->len, off + header->len + 22);
+#define FINDSTR(addr, str) (!strncmp((char*)addr, str, strlen(str)))
 
-       printf("Identifier: %.4s\n", header->ident);
-
-       printf("Offset: 0x%08x\n", header->offset);
+void handle_defaults(unsigned char *fw, int len, int patch)
+{
+       int i;
 
-       printf("Descriptiom: %s\n", header->desc);
+       for (i = 0; i < (len-100 /* XXX */); i++) {
+               if (FINDSTR(fw+i, "/default/fw_prop/") ||
+                   FINDSTR(fw+i, "/default/fw_setup/") ||
+                   FINDSTR(fw+i, "/default/oem_prop/")) {
+                       unsigned char *pos = fw + i;
+                       unsigned char type1, type2;
+                       unsigned char right_rw, rw_mask;
+                       unsigned char *val;
+
+                       printf("0x%08x: found setting: %s: ", i, pos);
+                       
+                       pos += strlen((char*)pos) + 1;
+
+                       if ((pos[0] != 0x11) ||
+                           (pos[1] != 0x11) ||
+                           (pos[2] != 0x01) ||
+                           (pos[3] != 0x83)) {
+                               printf("ignoring...\n");
+                               continue;
+                       }
+
+
+                       pos += 4;
+
+                       right_rw = pos[2];
+                       rw_mask = pos[3];
+
+                       type1 = pos[4];
+                       type2 = pos[8];
+                       val = pos + 9;
+
+                       if (type1 == 0x00 && type2 == 0x04) {
+                               printf("STRING: %s ", val);
+                       } else if (type1 == 0x01 && type2 == 0x01) {
+                               printf("BOOL: %s ",(*val ? "TRUE" : "FALSE"));
+                       } else if (type1 == 0x04 && type2 == 0x02) {
+                               printf("VAL: 0x%x ", *((unsigned int*)val));
+                       } else {
+                               printf("0x%02x 0x%2x...ignoring\n", type1, type2);
+                               continue;
+                       }
+
+                       if (right_rw == 0x00 && rw_mask == 0x00) {
+                               printf("(R-) ");
+                       } else if (right_rw == 0x01) {
+                               printf("(RW mask: 0x%02x) ", rw_mask);
+                       } else {
+                               printf("(UNK 0x%02x 0x%02x) ", right_rw, rw_mask);
+                       }
+                       printf("\n");
+               }
+       }
+}
 
-       printf("\n");
-       last_off = off;
+void handle_boarddescription(unsigned char *fw, int len, int patch)
+{
+       /* 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 */
 }
 
 int main(int argc, char **argv)
@@ -47,7 +81,7 @@ int main(int argc, char **argv)
        int fd;
        int remaining;
        int ret;
-       unsigned int crc;
+       unsigned int crc, oldcrc;
 
        if (argc != 2) {
                fprintf(stderr,"Syntax: %s firmware.bin\n", argv[0]);
@@ -81,15 +115,22 @@ int main(int argc, char **argv)
                remaining -= ret;
        }
 
-#if 0
-       parse_fw(fw, 0x0);
-       parse_fw(fw, 0x555c0);
-       parse_fw(fw, 0x5940e);
-#endif
-
-       crc = rsb_crc(0, fw, statbuf.st_size-4);
-
-       printf("Length: %ld, Checksum: 0x%08x\n", statbuf.st_size-4, crc);
+       ret = rsb_crc2(fw, statbuf.st_size, 0x55335053, &crc);
+       oldcrc = (unsigned int)*((unsigned int*)(fw + statbuf.st_size - 4));
+
+       printf("Checksum: 0x%08x (%s), should be: 0x%08x\n",
+               crc,
+               (ret ? "NOT OK" : "OK"),
+               oldcrc);
+       
+       if (1) {
+               handle_defaults(fw, statbuf.st_size - 4, 0);
+               handle_boarddescription(fw, statbuf.st_size - 4, 0);
+               if (0) {
+                       ret = rsb_crc2(fw, statbuf.st_size, 0x55335053, &crc);
+                       printf("Checksum: 0x%08x\n", crc);
+               }
+       }
 
        exit(0);
 }
Impressum, Datenschutz