b43-fwcutter: unsupported file support
authorJohannes Berg <johannes@sipsolutions.net>
Fri, 23 Nov 2007 11:17:26 +0000 (12:17 +0100)
committerMichael Buesch <mb@bu3sch.de>
Fri, 23 Nov 2007 13:54:10 +0000 (14:54 +0100)
This patch makes fwcutter support only those files we know are working
and marks the other one unsupported. To allow developers to still work
with such files, an --unsupported command line option is added that
allows one to extract firmware from such unsupported files. Some code
restructuring was necessary to support the --unsupported flag with other
flags in any order.

Also, because this is a significant change, bump the version number.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Michael Buesch <mb@bu3sch.de>
fwcutter/Makefile
fwcutter/fwcutter.c
fwcutter/fwcutter.h
fwcutter/fwcutter_list.h

index 2ddd8bd7387ef07669ef9b0c92b8d826541ea2e0..29d9b5e8e599c1bd5999b4d2f56a81d620b7bf71 100644 (file)
@@ -1,4 +1,4 @@
-VERSION = 008
+VERSION = 009
 
 CC ?= cc
 PREFIX ?= /usr/local
 
 CC ?= cc
 PREFIX ?= /usr/local
index fef90990453814672422af3e63d39bc45de8711f..ae1c63a48c18c40416a0b3104f3a8fd54e0729ee 100644 (file)
 static struct cmdline_args cmdargs;
 
 
 static struct cmdline_args cmdargs;
 
 
+/* check whether file will be listed/extracted from */
+static int file_ok(const struct file *f)
+{
+       return !(f->flags & FW_FLAG_UNSUPPORTED) || cmdargs.unsupported;
+}
+
 /* Convert a CPU-endian 16bit integer to Big-Endian */
 static be16_t to_be16(uint16_t v)
 {
 /* Convert a CPU-endian 16bit integer to Big-Endian */
 static be16_t to_be16(uint16_t v)
 {
@@ -398,7 +404,7 @@ static void extract_or_identify(FILE *f, const struct extract *extract,
                exit(255);
        }
 
                exit(255);
        }
 
-       if (!cmdargs.identify_only)
+       if (cmdargs.mode == FWCM_EXTRACT)
                write_file(extract->name, buf, data_length, &hdr, flags);
 
        free(buf);
                write_file(extract->name, buf, data_length, &hdr, flags);
 
        free(buf);
@@ -449,10 +455,10 @@ static void print_supported_files(void)
               "<MD5 checksum>\n\n");
        /* print for legacy driver first */
        for (i = 0; i < FILES; i++)
               "<MD5 checksum>\n\n");
        /* print for legacy driver first */
        for (i = 0; i < FILES; i++)
-               if (!(files[i].flags & FW_FLAG_V4))
+               if (file_ok(&files[i]) && !(files[i].flags & FW_FLAG_V4))
                        print_file(&files[i]);
        for (i = 0; i < FILES; i++)
                        print_file(&files[i]);
        for (i = 0; i < FILES; i++)
-               if (files[i].flags & FW_FLAG_V4)
+               if (file_ok(&files[i]) && files[i].flags & FW_FLAG_V4)
                        print_file(&files[i]);
        printf("\n");
 }
                        print_file(&files[i]);
        printf("\n");
 }
@@ -478,7 +484,8 @@ static const struct file *find_file(FILE *fd)
                 signature[12], signature[13], signature[14], signature[15]);
 
        for (i = 0; i < FILES; ++i) {
                 signature[12], signature[13], signature[14], signature[15]);
 
        for (i = 0; i < FILES; ++i) {
-               if (strcasecmp(md5sig, files[i].md5) == 0) {
+               if (file_ok(&files[i]) &&
+                   strcasecmp(md5sig, files[i].md5) == 0) {
                        printf("This file is recognised as:\n");
                        printf("  filename   :  %s\n", files[i].name);
                        printf("  version    :  %s\n", files[i].ucode_version);
                        printf("This file is recognised as:\n");
                        printf("  filename   :  %s\n", files[i].name);
                        printf("  version    :  %s\n", files[i].ucode_version);
@@ -497,6 +504,8 @@ static void print_usage(int argc, char *argv[])
 {
        print_banner();
        printf("\nUsage: %s [OPTION] [driver.sys]\n", argv[0]);
 {
        print_banner();
        printf("\nUsage: %s [OPTION] [driver.sys]\n", argv[0]);
+       printf("  --unsupported         "
+              "Allow working on extractable but unsupported drivers\n");
        printf("  -l|--list             "
               "List supported driver versions\n");
        printf("  -i|--identify         "
        printf("  -l|--list             "
               "List supported driver versions\n");
        printf("  -i|--identify         "
@@ -584,8 +593,8 @@ static int parse_args(int argc, char *argv[])
        for (i = 1; i < argc; i++) {
                res = cmp_arg(argv, &i, "--list", "-l", 0);
                if (res == ARG_MATCH) {
        for (i = 1; i < argc; i++) {
                res = cmp_arg(argv, &i, "--list", "-l", 0);
                if (res == ARG_MATCH) {
-                       print_supported_files();
-                       return 1;
+                       cmdargs.mode = FWCM_LIST;
+                       continue;
                } else if (res == ARG_ERROR)
                        goto out;
 
                } else if (res == ARG_ERROR)
                        goto out;
 
@@ -604,7 +613,14 @@ static int parse_args(int argc, char *argv[])
 
                res = cmp_arg(argv, &i, "--identify", "-i", 0);
                if (res == ARG_MATCH) {
 
                res = cmp_arg(argv, &i, "--identify", "-i", 0);
                if (res == ARG_MATCH) {
-                       cmdargs.identify_only = 1;
+                       cmdargs.mode = FWCM_IDENTIFY;
+                       continue;
+               } else if (res == ARG_ERROR)
+                       goto out;
+
+               res = cmp_arg(argv, &i, "--unsupported", NULL, 0);
+               if (res == ARG_MATCH) {
+                       cmdargs.unsupported = 1;
                        continue;
                } else if (res == ARG_ERROR)
                        goto out;
                        continue;
                } else if (res == ARG_ERROR)
                        goto out;
@@ -620,7 +636,7 @@ static int parse_args(int argc, char *argv[])
                break;
        }
 
                break;
        }
 
-       if (!cmdargs.infile)
+       if (!cmdargs.infile && cmdargs.mode != FWCM_LIST)
                goto out_usage;
        return 0;
 
                goto out_usage;
        return 0;
 
@@ -645,6 +661,11 @@ int main(int argc, char *argv[])
        else if (err != 0)
                return err;
 
        else if (err != 0)
                return err;
 
+       if (cmdargs.mode == FWCM_LIST) {
+               print_supported_files();
+               return 0;
+       }
+
        fd = fopen(cmdargs.infile, "rb");
        if (!fd) {
                fprintf(stderr, "Cannot open input file %s\n", cmdargs.infile);
        fd = fopen(cmdargs.infile, "rb");
        if (!fd) {
                fprintf(stderr, "Cannot open input file %s\n", cmdargs.infile);
@@ -664,7 +685,7 @@ int main(int argc, char *argv[])
        extract = file->extract;
        while (extract->name) {
                printf("%s %s/%s.fw\n",
        extract = file->extract;
        while (extract->name) {
                printf("%s %s/%s.fw\n",
-                      cmdargs.identify_only ? "Contains" : "Extracting",
+                      cmdargs.mode == FWCM_IDENTIFY ? "Contains" : "Extracting",
                       dir, extract->name);
                extract_or_identify(fd, extract, file->flags);
                extract++;
                       dir, extract->name);
                extract_or_identify(fd, extract, file->flags);
                extract++;
index 2f23d81d3f98c128fc54fdc728a554f4f7f6a961..2e47073cc7db47def23717b6e33fce13303f659e 100644 (file)
@@ -1,8 +1,9 @@
 #ifndef _FWCUTTER_H_
 #define _FWCUTTER_H_
 
 #ifndef _FWCUTTER_H_
 #define _FWCUTTER_H_
 
-#define FW_FLAG_LE     0x01    /* little endian? convert */
-#define FW_FLAG_V4     0x02    /* b43 vs. b43legacy */
+#define FW_FLAG_LE             0x01    /* little endian? convert */
+#define FW_FLAG_V4             0x02    /* b43 vs. b43legacy */
+#define FW_FLAG_UNSUPPORTED    0x04    /* not supported/working */
 
 #define fwcutter_stringify_1(x)        #x
 #define fwcutter_stringify(x)  fwcutter_stringify_1(x)
 
 #define fwcutter_stringify_1(x)        #x
 #define fwcutter_stringify(x)  fwcutter_stringify_1(x)
@@ -20,10 +21,17 @@ typedef uint32_t be32_t; /* Big-endian 32bit */
 #define ARG_NOMATCH    1
 #define ARG_ERROR      -1
 
 #define ARG_NOMATCH    1
 #define ARG_ERROR      -1
 
+enum fwcutter_mode {
+       FWCM_EXTRACT = 0,       /* default */
+       FWCM_LIST,
+       FWCM_IDENTIFY,
+};
+
 struct cmdline_args {
        const char *infile;
        const char *target_dir;
 struct cmdline_args {
        const char *infile;
        const char *target_dir;
-       int identify_only;
+       enum fwcutter_mode mode;
+       int unsupported;
 };
 
 struct insn {
 };
 
 struct insn {
index c3631ce24ec67709abfac82b5229c024ec1362a6..bed370ad89141457ee32e2ffc5a0bbffc74630b4 100644 (file)
@@ -147,7 +147,7 @@ static const struct file files[] =
                .name           = "wl_ap.o",
                .ucode_version  = "410.2160",
                .md5            = "1e4763b4cb8cfbaae43e5c6d3d6b2ae7",
                .name           = "wl_ap.o",
                .ucode_version  = "410.2160",
                .md5            = "1e4763b4cb8cfbaae43e5c6d3d6b2ae7",
-               .flags          = FW_FLAG_LE | FW_FLAG_V4,
+               .flags          = FW_FLAG_LE | FW_FLAG_V4 | FW_FLAG_UNSUPPORTED,
                .extract        = _1e4763b4cb8cfbaae43e5c6d3d6b2ae7,
        },
 };
                .extract        = _1e4763b4cb8cfbaae43e5c6d3d6b2ae7,
        },
 };