]> git.zerfleddert.de Git - rsbs2/blobdiff - firmware.c
add stub for adding/replacing files in the firmware image
[rsbs2] / firmware.c
index fb5b007e5b2b8e9e3968c740286b90d01f8a8ed2..16b86183431ebd89bdba766af34f4710b75fd708 100644 (file)
@@ -8,7 +8,7 @@
 #include <string.h>
 #include <strings.h>
 #include "rsb-crc.h"
 #include <string.h>
 #include <strings.h>
 #include "rsb-crc.h"
-#include "extract.h"
+#include "filesystem.h"
 
 #define FINDSTR(addr, str) (!strncmp((char*)addr, str, strlen(str)))
 
 
 #define FINDSTR(addr, str) (!strncmp((char*)addr, str, strlen(str)))
 
@@ -259,14 +259,15 @@ void syntax(char *name)
 {
        fprintf(stderr,"Syntax: %s parameters firmware.bin\n", name);
        fprintf(stderr,"parameters as follows:\n");
 {
        fprintf(stderr,"Syntax: %s parameters firmware.bin\n", name);
        fprintf(stderr,"parameters as follows:\n");
-       fprintf(stderr,"\t-d\t\tdisplay all properties of the image\n");
-       fprintf(stderr,"\t-u\t\tupdate checksum of the image\n");
-       fprintf(stderr,"\t-b\t\tmodify BOARD_DESCRIPTION for more power-switch options\n");
-       fprintf(stderr,"\t-e\t\textract files in firmware\n");
-       fprintf(stderr,"\t-t property\tset 'property' to true\n");
-       fprintf(stderr,"\t-f property\tset 'property' to false\n");
-       fprintf(stderr,"\t-w property\tallow read-write access to 'property'\n");
-       fprintf(stderr,"\t-r property\tallow read-only access to 'property'\n");
+       fprintf(stderr,"\t-d\t\t\tdisplay all properties of the image\n");
+       fprintf(stderr,"\t-u\t\t\tupdate checksum of the image\n");
+       fprintf(stderr,"\t-b\t\t\tmodify BOARD_DESCRIPTION for more power-switch options\n");
+       fprintf(stderr,"\t-e\t\t\textract files in firmware\n");
+       fprintf(stderr,"\t-t property\t\tset 'property' to true\n");
+       fprintf(stderr,"\t-f property\t\tset 'property' to false\n");
+       fprintf(stderr,"\t-w property\t\tallow read-write access to 'property'\n");
+       fprintf(stderr,"\t-r property\t\tallow read-only access to 'property'\n");
+       fprintf(stderr,"\t-x fw_file=local_file\treplace or add fw_file with content of local_file\n");
        exit(1);
 }
 
        exit(1);
 }
 
@@ -345,22 +346,17 @@ int check_crc(unsigned char *fw, int len)
        return ret;
 }
 
        return ret;
 }
 
-int check_image(unsigned char *fw, int len)
+void check_image(unsigned char *fw, int len)
 {
        struct file_entry *fent;
        char *last_name = NULL;
 
 {
        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);
        }
        fent = get_next_file(fw, len);
        while (fent != NULL) {
                last_name = fent->name;
                fent = get_next_file(NULL, 0);
        }
-
-       if (strcmp(last_name, "pdata")) {
-               return 1;
-       }
-
-       return 0;
 }
 
 int main(int argc, char **argv)
 }
 
 int main(int argc, char **argv)
@@ -383,7 +379,7 @@ int main(int argc, char **argv)
        if (argc < 2)
                syntax(argv[0]);
 
        if (argc < 2)
                syntax(argv[0]);
 
-       while ((opt = getopt(argc, argv, "dubet:f:w:r:")) != -1) {
+       while ((opt = getopt(argc, argv, "dubet:f:w:r:x:")) != -1) {
                switch(opt) {
                        case 'd':
                                showall = 1;
                switch(opt) {
                        case 'd':
                                showall = 1;
@@ -404,6 +400,9 @@ int main(int argc, char **argv)
                                patch_fw = 1;
                                add_action(opt, optarg, &paction);
                                break;
                                patch_fw = 1;
                                add_action(opt, optarg, &paction);
                                break;
+                       case 'x':
+                               replace_add_file(NULL, 0, NULL, NULL);
+                               break;
                        default:
                                syntax(argv[0]);
                }
                        default:
                                syntax(argv[0]);
                }
@@ -451,15 +450,12 @@ int main(int argc, char **argv)
                exit(1);
        }
 
                exit(1);
        }
 
-       if (check_image(fw, statbuf.st_size-4) != 0) {
-               fprintf(stderr, "corrupt firmware image found (pdata is not last entry), aborting!\n");
-               exit(1);
-       }
+       check_image(fw, statbuf.st_size - 4);
 
        if (patch_fw) {
                struct propaction *cpaction = paction;
 
 
        if (patch_fw) {
                struct propaction *cpaction = paction;
 
-               change_properties(fw, statbuf.st_size, paction);
+               change_properties(fw, statbuf.st_size - 4, paction);
 
                printf("\nProperty change results:\n");
                while(cpaction != NULL) {
 
                printf("\nProperty change results:\n");
                while(cpaction != NULL) {
@@ -483,12 +479,12 @@ int main(int argc, char **argv)
        }
 
        if (patch_bd) {
        }
 
        if (patch_bd) {
-               handle_boarddescription(fw, statbuf.st_size -4, 1);
+               handle_boarddescription(fw, statbuf.st_size - 4, 1);
        }
 
        if (showall) {
                show_properties(fw, statbuf.st_size - 4);
        }
 
        if (showall) {
                show_properties(fw, statbuf.st_size - 4);
-               handle_boarddescription(fw, statbuf.st_size -4, 0);
+               handle_boarddescription(fw, statbuf.st_size - 4, 0);
        }
 
        if (extract) {
        }
 
        if (extract) {
@@ -501,6 +497,8 @@ int main(int argc, char **argv)
                        *((unsigned int*)(fw + statbuf.st_size - 4)) = crc;
                }
 
                        *((unsigned int*)(fw + statbuf.st_size - 4)) = crc;
                }
 
+               check_image(fw, statbuf.st_size-4);
+
                if (check_crc(fw, statbuf.st_size) == 0) {
                        char *newfile;
 
                if (check_crc(fw, statbuf.st_size) == 0) {
                        char *newfile;
 
@@ -514,7 +512,7 @@ int main(int argc, char **argv)
 
                        printf("Writing %s\n", newfile);
                        if ((fd = open(newfile, O_WRONLY|O_CREAT, 0644)) == -1) {
 
                        printf("Writing %s\n", newfile);
                        if ((fd = open(newfile, O_WRONLY|O_CREAT, 0644)) == -1) {
-                               fprintf(stderr,"%s: ", file);
+                               fprintf(stderr,"%s: ", newfile);
                                perror("open");
                                exit(1);
                        }
                                perror("open");
                                exit(1);
                        }
Impressum, Datenschutz