#include <unistd.h>
-int _debug;
-bool arg_print_sizes;
-const char *initvals_fn_extension = ".initvals";
-static const char *real_infile_name;
-enum fwformat output_format = FMT_B43;
+struct cmdline_args cmdargs = {
+ .debug = 0,
+ .print_sizes = 0,
+ .initvals_fn_extension = ".initvals",
+ .outformat = FMT_B43,
+};
#define ARG_MATCH 0
return 1;
} else if ((res = cmp_arg(argv, &i, "--format", "-f", ¶m)) == ARG_MATCH) {
if (strcasecmp(param, "raw-le32") == 0)
- output_format = FMT_RAW_LE32;
+ cmdargs.outformat = FMT_RAW_LE32;
else if (strcasecmp(param, "raw-be32") == 0)
- output_format = FMT_RAW_BE32;
+ cmdargs.outformat = FMT_RAW_BE32;
else if (strcasecmp(param, "b43") == 0)
- output_format = FMT_B43;
+ cmdargs.outformat = FMT_B43;
else {
fprintf(stderr, "Invalid -f|--format\n\n");
goto out_usage;
}
} else if ((res = cmp_arg(argv, &i, "--debug", "-d", NULL)) == ARG_MATCH) {
- _debug++;
+ cmdargs.debug++;
} else if ((res = cmp_arg(argv, &i, "--psize", "-s", NULL)) == ARG_MATCH) {
- arg_print_sizes = 1;
- } else if ((res = cmp_arg(argv, &i, "--ivalext", "-e", &initvals_fn_extension)) == ARG_MATCH) {
- /* initvals_fn_extension is set to the extension. */
- } else if ((res = cmp_arg(argv, &i, "--__real_infile", NULL, &real_infile_name)) == ARG_MATCH) {
- /* real_infile_name is set. */
+ cmdargs.print_sizes = 1;
+ } else if ((res = cmp_arg(argv, &i, "--ivalext", "-e", ¶m)) == ARG_MATCH) {
+ cmdargs.initvals_fn_extension = param;
+ } else if ((res = cmp_arg(argv, &i, "--__real_infile", NULL, ¶m)) == ARG_MATCH) {
+ cmdargs.real_infile_name = param;
} else {
fprintf(stderr, "Unrecognized argument: %s\n", argv[i]);
goto out_usage;
}
}
- if (!real_infile_name)
- real_infile_name = infile_name;
- if (strcmp(real_infile_name, outfile_name) == 0) {
+ if (!cmdargs.real_infile_name)
+ cmdargs.real_infile_name = infile_name;
+ if (strcmp(cmdargs.real_infile_name, outfile_name) == 0) {
fprintf(stderr, "Error: INPUT and OUTPUT filename must not be the same\n");
goto out_usage;
}
FMT_B43, /* b43/b43legacy headers. */
};
+struct cmdline_args {
+ int debug; /* Debug level. */
+ bool print_sizes; /* Print sizes after assembling. */
+ const char *initvals_fn_extension; /* Initvals filename extension. */
+ const char *real_infile_name; /* The real input file name. */
+ enum fwformat outformat; /* The output file format. */
+};
+
int parse_args(int argc, char **argv);
int open_input_file(void);
void close_input_file(void);
-extern int _debug;
-extern bool arg_print_sizes;
-extern const char *initvals_fn_extension;
-extern enum fwformat output_format;
+extern struct cmdline_args cmdargs;
-#define IS_DEBUG (_debug > 0)
-#define IS_VERBOSE_DEBUG (_debug > 1)
-#define IS_INSANE_DEBUG (_debug > 2)
+#define IS_DEBUG (cmdargs.debug > 0)
+#define IS_VERBOSE_DEBUG (cmdargs.debug > 1)
+#define IS_INSANE_DEBUG (cmdargs.debug > 2)
#endif /* BCM43xx_ASM_ARGS_H_ */
hdr.ver = FW_HDR_VER;
hdr.size = cpu_to_be32(ctx->ivals_count);
- fn_len = strlen(ctx->sect->name) + strlen(initvals_fn_extension ? : "") + 1;
+ fn_len = strlen(ctx->sect->name) + strlen(cmdargs.initvals_fn_extension ? : "") + 1;
fn = xmalloc(fn_len);
- snprintf(fn, fn_len, "%s%s", ctx->sect->name, initvals_fn_extension ? : "");
+ snprintf(fn, fn_len, "%s%s", ctx->sect->name, cmdargs.initvals_fn_extension ? : "");
fd = fopen(fn, "w+");
if (!fd) {
fprintf(stderr, "Could not open initval output file \"%s\"\n", fn);
filesize += size;
}
- if (arg_print_sizes) {
+ if (cmdargs.print_sizes) {
printf("%s: %d values (%u bytes)\n",
fn, ctx->ivals_count, filesize);
}