]> cvs.zerfleddert.de Git - rsbs2/blobdiff - firmware.c
use unified write_file function everywhere...
[rsbs2] / firmware.c
index 16b86183431ebd89bdba766af34f4710b75fd708..b57501277aa90b091d189e7fec940696c8d19458 100644 (file)
@@ -263,6 +263,7 @@ void syntax(char *name)
        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-l\t\t\tlist 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");
@@ -375,11 +376,12 @@ int main(int argc, char **argv)
        int patch_bd = 0;
        int patch_fw = 0;
        int extract = 0;
+       int list = 0;
 
        if (argc < 2)
                syntax(argv[0]);
 
-       while ((opt = getopt(argc, argv, "dubet:f:w:r:x:")) != -1) {
+       while ((opt = getopt(argc, argv, "dubelt:f:w:r:x:")) != -1) {
                switch(opt) {
                        case 'd':
                                showall = 1;
@@ -393,6 +395,9 @@ int main(int argc, char **argv)
                        case 'e':
                                extract = 1;
                                break;
+                       case 'l':
+                               list = 1;
+                               break;
                        case 't':
                        case 'f':
                        case 'w':
@@ -487,6 +492,10 @@ int main(int argc, char **argv)
                handle_boarddescription(fw, statbuf.st_size - 4, 0);
        }
 
+       if (list) {
+               list_files(fw, statbuf.st_size - 4);
+       }
+
        if (extract) {
                extract_files(fw, statbuf.st_size - 4);
        }
@@ -510,23 +519,8 @@ int main(int argc, char **argv)
                        strcpy(newfile, file);
                        strcat(newfile, ".patched");
 
-                       printf("Writing %s\n", newfile);
-                       if ((fd = open(newfile, O_WRONLY|O_CREAT, 0644)) == -1) {
-                               fprintf(stderr,"%s: ", newfile);
-                               perror("open");
-                               exit(1);
-                       }
-
-                       remaining = statbuf.st_size;
-
-                       while(remaining) {
-                               if ((ret = write(fd, fw + (statbuf.st_size - remaining), remaining)) == -1) {
-                                       perror("write");
-                                       exit(1);
-                               }
-                               remaining -= ret;
-                       }
-                       close(fd);
+                       printf("Firmware ");
+                       write_file(newfile, fw, statbuf.st_size);
                } else {
                        fprintf(stderr,"Can't set correct checksum, aborting...\n");
                }
Impressum, Datenschutz