From: Michael Buesch Date: Thu, 22 May 2008 12:42:29 +0000 (+0200) Subject: b43-asm: Change the filenames of the binaries. X-Git-Tag: b43-fwcutter-013~52 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=ff7327cd416e9892b175af85c2641d425d256e70;p=b43-tools.git b43-asm: Change the filenames of the binaries. Signed-off-by: Michael Buesch --- diff --git a/assembler/args.c b/assembler/args.c index cf49460..a673654 100644 --- a/assembler/args.c +++ b/assembler/args.c @@ -24,6 +24,9 @@ int _debug; bool arg_print_sizes; +const char *initvals_fn_extension = ".initvals"; +const char *real_infile_name; + #define ARG_MATCH 0 #define ARG_NOMATCH 1 @@ -32,7 +35,7 @@ bool arg_print_sizes; static int do_cmp_arg(char **argv, int *pos, const char *template, int allow_merged, - char **param) + const char **param) { char *arg; char *next_arg; @@ -76,7 +79,7 @@ static int do_cmp_arg(char **argv, int *pos, static int cmp_arg(char **argv, int *pos, const char *long_template, const char *short_template, - char **param) + const char **param) { int err; @@ -93,11 +96,12 @@ static int cmp_arg(char **argv, int *pos, static void usage(int argc, char **argv) { - fprintf(stderr, "Usage: %s INPUT_FILE OUTPUT_FILE [OPTIONS]\n", argv[0]); - fprintf(stderr, " -h|--help Print this help\n"); - fprintf(stderr, " -d|--debug Print verbose debugging info\n"); - fprintf(stderr, " Repeat for more verbose debugging\n"); - fprintf(stderr, " -s|--psize Print the size of the code after assembling\n"); + printf("Usage: %s INPUT_FILE OUTPUT_FILE [OPTIONS]\n", argv[0]); + printf(" -h|--help Print this help\n"); + printf(" -d|--debug Print verbose debugging info\n"); + printf(" Repeat for more verbose debugging\n"); + printf(" -s|--psize Print the size of the code after assembling\n"); + printf(" -e|--ivalext EXT Filename extension for the initvals\n"); } int parse_args(int argc, char **argv) @@ -118,11 +122,22 @@ int parse_args(int argc, char **argv) _debug++; } else if ((res = cmp_arg(argv, &i, "--psize", "-s", 0)) == 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", 0, &real_infile_name)) == ARG_MATCH) { + /* real_infile_name is set. */ } 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) { + fprintf(stderr, "Error: INPUT and OUTPUT filename must not be the same\n"); + goto out_usage; + } + return 0; out_usage: usage(argc, argv); diff --git a/assembler/args.h b/assembler/args.h index 15fcb51..06f8ca3 100644 --- a/assembler/args.h +++ b/assembler/args.h @@ -10,6 +10,7 @@ void close_input_file(void); extern int _debug; extern bool arg_print_sizes; +extern const char *initvals_fn_extension; #define IS_DEBUG (_debug > 0) #define IS_VERBOSE_DEBUG (_debug > 1) diff --git a/assembler/b43-asm b/assembler/b43-asm index 2fbccce..11e7719 100755 --- a/assembler/b43-asm +++ b/assembler/b43-asm @@ -48,4 +48,4 @@ if [ "$infile" != "-" ]; then fi fi -$CPP -x c++ -traditional-cpp "$infile" | $B43_ASM "-" "$outfile" $@ +$CPP -x c++ -traditional-cpp "$infile" | $B43_ASM "-" "$outfile" --__real_infile "$infile" $@ diff --git a/assembler/initvals.c b/assembler/initvals.c index eb39d73..b403563 100644 --- a/assembler/initvals.c +++ b/assembler/initvals.c @@ -283,9 +283,9 @@ static void emit_ival_section(struct ivals_context *ctx) hdr.ver = FW_HDR_VER; hdr.size = cpu_to_be32(ctx->ivals_count); - fn_len = strlen(outfile_name) + 512; + fn_len = strlen(ctx->sect->name) + strlen(initvals_fn_extension ? : "") + 1; fn = xmalloc(fn_len); - snprintf(fn, fn_len, "%s.%s.initvals", outfile_name, ctx->sect->name); + snprintf(fn, fn_len, "%s%s", ctx->sect->name, initvals_fn_extension ? : ""); fd = fopen(fn, "w+"); if (!fd) { fprintf(stderr, "Could not open initval output file \"%s\"\n", fn); diff --git a/assembler/main.c b/assembler/main.c index 255cabc..ab79f7e 100644 --- a/assembler/main.c +++ b/assembler/main.c @@ -1026,21 +1026,17 @@ does_not_exist: static void emit_code(struct assembler_context *ctx) { FILE *fd; - char *fn; - size_t fn_len; + const char *fn; struct code_output *c; uint64_t code; unsigned char outbuf[8]; unsigned int insn_count = 0; struct fw_header hdr; - fn_len = strlen(outfile_name) + 20; - fn = xmalloc(fn_len); - snprintf(fn, fn_len, "%s.ucode", outfile_name); + fn = outfile_name; fd = fopen(fn, "w+"); if (!fd) { fprintf(stderr, "Could not open microcode output file \"%s\"\n", fn); - free(fn); exit(1); } if (IS_VERBOSE_DEBUG) @@ -1132,7 +1128,6 @@ static void emit_code(struct assembler_context *ctx) } fclose(fd); - free(fn); } static void assemble(void)