]> git.zerfleddert.de Git - rsbs2/blobdiff - src/firmware.c
firmware: update for 64bit platforms
[rsbs2] / src / firmware.c
index b57501277aa90b091d189e7fec940696c8d19458..533f04dc5eae7c73e7027dc4ce04e5a3b86ec5c0 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #define FINDSTR(addr, str) (!strncmp((char*)addr, str, strlen(str)))
 
 struct properties {
-       unsigned int magic;
-       unsigned char unknown0;
-       unsigned char unknown1;
-       unsigned char right_rw;
-       unsigned char rw_mask;
-       unsigned char type1;
-       unsigned char unknown5;
-       unsigned char unknown6;
-       unsigned char unknown7;
-       unsigned char type2;
-       unsigned char val[];
+       uint32_t magic;
+       uint8_t unknown0;
+       uint8_t unknown1;
+       uint8_t right_rw;
+       uint8_t rw_mask;
+       uint8_t type1;
+       uint8_t unknown5;
+       uint8_t unknown6;
+       uint8_t unknown7;
+       uint8_t type2;
+       uint8_t val[];
 };
 
 #define PROP_ACTION_TRUE       (1<<0)
@@ -39,12 +40,12 @@ struct properties {
 
 struct propaction {
        char *property;
-       unsigned int action;
-       unsigned int status;
+       uint32_t action;
+       uint32_t status;
        struct propaction *next;
 };
 
-void show_properties(unsigned char *fw, int len)
+void show_properties(uint8_t *fw, int32_t len)
 {
        struct file_entry *fent;
 
@@ -54,7 +55,7 @@ void show_properties(unsigned char *fw, int len)
                    FINDSTR(fent->name, "/default/oem_prop/")) {
                        struct properties *prop;
 
-                       printf("0x%08x: found setting: %s ", fent->start - fw, fent->name);
+                       printf("0x%08x: found setting: %s ", (uint32_t)(fent->start - fw), fent->name);
 
                        prop = (struct properties*)fent->start;
                        
@@ -68,7 +69,10 @@ void show_properties(unsigned char *fw, int len)
                        } else if (prop->type1 == 0x01 && prop->type2 == 0x01) {
                                printf("BOOL: %s ",(*prop->val ? "TRUE" : "FALSE"));
                        } else if (prop->type1 == 0x04 && prop->type2 == 0x02) {
-                               printf("VAL: 0x%x ", *((unsigned int*)prop->val));
+                               uint32_t val;
+
+                               memcpy(&val, prop->val, 4);
+                               printf("VAL: 0x%x ", val);
                        } else {
                                printf("0x%02x 0x%2x...ignoring\n", prop->type1, prop->type2);
                                continue;
@@ -86,7 +90,7 @@ void show_properties(unsigned char *fw, int len)
        }
 }
 
-void change_properties(unsigned char *fw, int len, struct propaction *paction)
+void change_properties(uint8_t *fw, int32_t len, struct propaction *paction)
 {
        struct file_entry *fent;
        struct propaction *cpaction;
@@ -178,9 +182,9 @@ void change_properties(unsigned char *fw, int len, struct propaction *paction)
 #define _BD_SET(bd, byte, bits) (bd[byte] |= bits)
 #define BD_SET(bd, ident) MAGIC(_BD_SET, bd, BD_##ident)
 
-void print_boarddescription(unsigned char *bd)
+void print_boarddescription(uint8_t *bd)
 {
-       int j;
+       int32_t j;
 
        for (j = 0; j < 32; j++) {
                printf("%02x ", *(bd+j));
@@ -214,10 +218,10 @@ void print_boarddescription(unsigned char *bd)
        printf("\tps2aPresent\t\t: %s\n", BD_TEXT(bd, PS2A));
 }
 
-void handle_boarddescription(unsigned char *fw, int len, int patch)
+void handle_boarddescription(uint8_t *fw, int32_t len, int32_t patch)
 {
        struct file_entry *fent;
-       unsigned char *pos;
+       uint8_t *pos;
        
        for (fent = get_next_file(fw, len); fent != NULL; fent = get_next_file(NULL, 0)) {
                if (!strcmp(fent->name, "pdata"))
@@ -232,7 +236,7 @@ void handle_boarddescription(unsigned char *fw, int len, int patch)
 
        pos = fent->start;
        /* MAGIC? */
-       if (*((unsigned int*)pos) != 0x00002802) {
+       if (*((uint32_t*)pos) != 0x00002802) {
                fprintf(stderr, "pdata magic does not match, aborting!\n");
                exit(1);
        }
@@ -240,7 +244,7 @@ void handle_boarddescription(unsigned char *fw, int len, int patch)
        pos += 26;
 
        /* MAGIC2? */
-       if (*((unsigned int*)pos) != 0x00500101) {
+       if (*((uint32_t*)pos) != 0x00500101) {
                fprintf(stderr, "pdata magic2 does not match, aborting!\n");
                exit(1);
        }
@@ -251,7 +255,7 @@ void handle_boarddescription(unsigned char *fw, int len, int patch)
                BD_SET(pos, PWRRELAY);
        }
 
-       printf("0x%08x: BOARD_DESCRIPTION: ", fent->start - fw);
+       printf("0x%08x: BOARD_DESCRIPTION: ", (uint32_t)(fent->start - fw));
        print_boarddescription(pos);
 }
 
@@ -272,7 +276,7 @@ void syntax(char *name)
        exit(1);
 }
 
-void add_action(int opt, char *optarg, struct propaction **paction) {
+void add_action(int32_t opt, char *optarg, struct propaction **paction) {
        struct propaction *pos = *paction;
        struct propaction *prev = NULL;
        
@@ -331,13 +335,13 @@ void add_action(int opt, char *optarg, struct propaction **paction) {
        }
 }
 
-int check_crc(unsigned char *fw, int len)
+int32_t check_crc(uint8_t *fw, int32_t len)
 {
-       int ret;
-       unsigned int crc, oldcrc;
+       int32_t ret;
+       uint32_t crc, oldcrc;
 
        ret = rsb_crc2(fw, len, 0x55335053, &crc);
-       oldcrc = (unsigned int)*((unsigned int*)(fw + len - 4));
+       oldcrc = (uint32_t)*((uint32_t*)(fw + len - 4));
 
        printf("Checksum: 0x%08x (%s), should be: 0x%08x\n",
                crc,
@@ -347,36 +351,34 @@ int check_crc(unsigned char *fw, int len)
        return ret;
 }
 
-void check_image(unsigned char *fw, int len)
+void check_image(uint8_t *fw, int32_t len)
 {
        struct file_entry *fent;
-       char *last_name = NULL;
 
        /* get_next_file will abort on error */
        fent = get_next_file(fw, len);
        while (fent != NULL) {
-               last_name = fent->name;
                fent = get_next_file(NULL, 0);
        }
 }
 
-int main(int argc, char **argv)
+int32_t main(int32_t argc, char **argv)
 {
        struct stat statbuf;
        char *file = NULL;
-       unsigned char *fw;
-       int fd;
-       int remaining;
-       int ret;
-       int opt;
-       unsigned int crc;
+       uint8_t *fw;
+       int32_t fd;
+       int32_t remaining;
+       int32_t ret;
+       int32_t opt;
+       uint32_t crc;
        struct propaction *paction = NULL;
-       int showall = 0;
-       int update_crc = 0;
-       int patch_bd = 0;
-       int patch_fw = 0;
-       int extract = 0;
-       int list = 0;
+       int32_t showall = 0;
+       int32_t update_crc = 0;
+       int32_t patch_bd = 0;
+       int32_t patch_fw = 0;
+       int32_t extract = 0;
+       int32_t list = 0;
 
        if (argc < 2)
                syntax(argv[0]);
@@ -503,7 +505,7 @@ int main(int argc, char **argv)
        if (update_crc || patch_fw || patch_bd) {
                ret = rsb_crc2(fw, statbuf.st_size, 0x55335053, &crc);
                if (ret == 4) {
-                       *((unsigned int*)(fw + statbuf.st_size - 4)) = crc;
+                       *((uint32_t*)(fw + statbuf.st_size - 4)) = crc;
                }
 
                check_image(fw, statbuf.st_size-4);
Impressum, Datenschutz