]> git.zerfleddert.de Git - rsbs2/blobdiff - firmware.c
rename extract.{c,h} to filesystem.{c,h}
[rsbs2] / firmware.c
index fb5b007e5b2b8e9e3968c740286b90d01f8a8ed2..9f599f39220e22be67d59ab715c82842308a3685 100644 (file)
@@ -8,7 +8,7 @@
 #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)))
 
@@ -345,22 +345,17 @@ int check_crc(unsigned char *fw, int len)
        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;
 
+       /* 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);
        }
-
-       if (strcmp(last_name, "pdata")) {
-               return 1;
-       }
-
-       return 0;
 }
 
 int main(int argc, char **argv)
@@ -451,15 +446,12 @@ int main(int argc, char **argv)
                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;
 
-               change_properties(fw, statbuf.st_size, paction);
+               change_properties(fw, statbuf.st_size - 4, paction);
 
                printf("\nProperty change results:\n");
                while(cpaction != NULL) {
@@ -483,12 +475,12 @@ int main(int argc, char **argv)
        }
 
        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);
-               handle_boarddescription(fw, statbuf.st_size -4, 0);
+               handle_boarddescription(fw, statbuf.st_size - 4, 0);
        }
 
        if (extract) {
@@ -501,6 +493,8 @@ int main(int argc, char **argv)
                        *((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;
 
@@ -514,7 +508,7 @@ int main(int argc, char **argv)
 
                        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);
                        }
Impressum, Datenschutz