From 6ccd7242c4c1404dafb64cd937adc3c65ce02385 Mon Sep 17 00:00:00 2001 From: Frank Haverkamp Date: Wed, 21 Jun 2006 14:26:02 +0200 Subject: [MTD] UBI: Removed automake, autoconf, added ubi userspace headers. Signed-off-by: Frank Haverkamp --- ubi-utils/src/nand2bin.c | 328 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 ubi-utils/src/nand2bin.c (limited to 'ubi-utils/src/nand2bin.c') diff --git a/ubi-utils/src/nand2bin.c b/ubi-utils/src/nand2bin.c new file mode 100644 index 0000000..a5e8bca --- /dev/null +++ b/ubi-utils/src/nand2bin.c @@ -0,0 +1,328 @@ +/* + * Copyright (c) International Business Machines Corp., 2006 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Frank Haverkamp + * + * An utility to decompose NAND images and strip OOB off. Not yet finished ... + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "nandecc.h" + +#define MAXPATH 1024 +#define MIN(x,y) ((x)<(y)?(x):(y)) + +struct args { + const char *oob_file; + const char *output_file; + size_t pagesize; + + /* special stuff needed to get additional arguments */ + char *arg1; + char **options; /* [STRING...] */ +}; + +static struct args myargs = { + .output_file = "data.bin", + .oob_file = "oob.bin", + .pagesize = 2048, + .arg1 = NULL, + .options = NULL, +}; + +static error_t parse_opt (int key, char *arg, struct argp_state *state); + +const char *argp_program_bug_address = PACKAGE_BUGREPORT; + +static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\t" + BUILD_OS" "BUILD_CPU" at "__DATE__" "__TIME__"\n" + "\nSplit data and OOB.\n"; + +static struct argp_option options[] = { + { .name = "pagesize", + .key = 'p', + .arg = "", + .flags = 0, + .doc = "NAND pagesize", + .group = OPTION_ARG_OPTIONAL }, + + { .name = "output", + .key = 'o', + .arg = "", + .flags = 0, + .doc = "Data output file", + .group = OPTION_ARG_OPTIONAL }, + + { .name = "oob", + .key = 'O', + .arg = "", + .flags = 0, + .doc = "OOB output file", + .group = OPTION_ARG_OPTIONAL }, + + { .name = NULL, .key = 0, .arg = NULL, .flags = 0, + .doc = NULL, .group = 0 }, +}; + +static struct argp argp = { + .options = options, + .parser = parse_opt, + .args_doc = "input.mif", + .doc = doc, + .children = NULL, + .help_filter = NULL, + .argp_domain = NULL, +}; + +/* + * str_to_num - Convert string into number and cope with endings like + * k, K, kib, KiB for kilobyte + * m, M, mib, MiB for megabyte + */ +uint32_t str_to_num(char *str) +{ + char *s = str; + ulong num = strtoul(s, &s, 0); + + if (*s != '\0') { + if (strcmp(s, "KiB") == 0) + num *= 1024; + else if (strcmp(s, "MiB") == 0) + num *= 1024*1024; + else { + fprintf(stderr, "WARNING: Wrong number format " + "\"%s\", check your paramters!\n", str); + } + } + return num; +} + +/* + * @brief Parse the arguments passed into the test case. + * + * @param key The parameter. + * @param arg Argument passed to parameter. + * @param state Location to put information on parameters. + * + * @return error + * + * Get the `input' argument from `argp_parse', which we know is a + * pointer to our arguments structure. + */ +static error_t +parse_opt(int key, char *arg, struct argp_state *state) +{ + struct args *args = state->input; + + switch (key) { + case 'p': /* --pagesize */ + args->pagesize = str_to_num(arg); break; + + case 'o': /* --output= */ + args->output_file = arg; + break; + + case 'O': /* --oob= */ + args->output_file = arg; + break; + + case ARGP_KEY_NO_ARGS: + /* argp_usage(state); */ + break; + + case ARGP_KEY_ARG: + args->arg1 = arg; + /* Now we consume all the rest of the arguments. + `state->next' is the index in `state->argv' of the + next argument to be parsed, which is the first STRING + we're interested in, so we can just use + `&state->argv[state->next]' as the value for + arguments->strings. + + _In addition_, by setting `state->next' to the end + of the arguments, we can force argp to stop parsing here and + return. */ + + args->options = &state->argv[state->next]; + state->next = state->argc; + break; + + case ARGP_KEY_END: + /* argp_usage(state); */ + break; + + default: + return(ARGP_ERR_UNKNOWN); + } + + return 0; +} + +static int calc_oobsize(size_t pagesize) +{ + switch (pagesize) { + case 512: return 16; + case 2048: return 64; + default: + exit(EXIT_FAILURE); + } + return 0; +} + +static inline void +hexdump(FILE *fp, const uint8_t *buf, ssize_t size) +{ + int k; + + for (k = 0; k < size; k++) { + fprintf(fp, "%02x ", buf[k]); + if ((k & 15) == 15) + fprintf(fp, "\n"); + } +} + +static int +process_page(uint8_t* buf, uint8_t *oobbuf, size_t pagesize) +{ + int eccpoi, oobsize; + size_t i; + + switch (pagesize) { + case 2048: oobsize = 64; eccpoi = 64 / 2; break; + case 512: oobsize = 16; eccpoi = 16 / 2; break; + default: + fprintf(stderr, "Unsupported page size: %d\n", pagesize); + return -EINVAL; + } + memset(oobbuf, 0xff, oobsize); + + for (i = 0; i < pagesize; i += 256, eccpoi += 3) { + oobbuf[eccpoi++] = 0x0; + /* Calculate ECC */ + nand_calculate_ecc(&buf[i], &oobbuf[eccpoi]); + } + return 0; +} + +static int decompose_image(FILE *in_fp, FILE *bin_fp, FILE *oob_fp, + size_t pagesize) +{ + int read, rc, page = 0; + size_t oobsize = calc_oobsize(pagesize); + uint8_t *buf = malloc(pagesize); + uint8_t *oob = malloc(oobsize); + uint8_t *calc_oob = malloc(oobsize); + uint8_t *calc_buf = malloc(pagesize); + + if (!buf) + exit(EXIT_FAILURE); + if (!oob) + exit(EXIT_FAILURE); + if (!calc_oob) + exit(EXIT_FAILURE); + if (!calc_buf) + exit(EXIT_FAILURE); + + while (!feof(in_fp)) { + read = fread(buf, 1, pagesize, in_fp); + if (ferror(in_fp)) { + fprintf(stderr, "I/O Error."); + exit(EXIT_FAILURE); + } + rc = fwrite(buf, 1, pagesize, bin_fp); + if (ferror(bin_fp)) { + fprintf(stderr, "I/O Error."); + exit(EXIT_FAILURE); + } + read = fread(oob, 1, oobsize, in_fp); + if (ferror(in_fp)) { + fprintf(stderr, "I/O Error."); + exit(EXIT_FAILURE); + } + rc = fwrite(oob, 1, oobsize, oob_fp); + if (ferror(bin_fp)) { + fprintf(stderr, "I/O Error."); + exit(EXIT_FAILURE); + } + process_page(buf, calc_oob, pagesize); + + memcpy(calc_buf, buf, pagesize); + + rc = nand_correct_data(calc_buf, oob); + if ((rc != -1) || (memcmp(buf, calc_buf, pagesize) != 0)) { + fprintf(stdout, "Page %d: data does not match!\n", + page); + } + page++; + } + free(calc_buf); + free(calc_oob); + free(oob); + free(buf); + return 0; +} + +int +main(int argc, char *argv[]) +{ + FILE *in, *bin, *oob; + + argp_parse(&argp, argc, argv, ARGP_IN_ORDER, 0, &myargs); + + if (!myargs.arg1) { + fprintf(stderr, "Please specify input file!\n"); + exit(EXIT_FAILURE); + } + + in = fopen(myargs.arg1, "r"); + if (!in) { + perror("Cannot open file"); + exit(EXIT_FAILURE); + } + bin = fopen(myargs.output_file, "w+"); + if (!bin) { + perror("Cannot open file"); + exit(EXIT_FAILURE); + } + oob = fopen(myargs.oob_file, "w+"); + if (!oob) { + perror("Cannot open file"); + exit(EXIT_FAILURE); + } + + decompose_image(in, bin, oob, myargs.pagesize); + + fclose(in); + fclose(bin); + fclose(oob); + + exit(EXIT_SUCCESS); +} -- cgit v1.2.3 From 8e584d752fb7fb40fe0dfa949c74d2522503d850 Mon Sep 17 00:00:00 2001 From: Josh Boyer Date: Mon, 11 Dec 2006 14:34:22 +0100 Subject: [PATCH 3/13] Convert nand2bin to use getopt option parsing Signed-off-by: Josh Boyer Acked-by: Frank Haverkamp --- ubi-utils/src/nand2bin.c | 148 +++++++++++++++++++++-------------------------- 1 file changed, 65 insertions(+), 83 deletions(-) (limited to 'ubi-utils/src/nand2bin.c') diff --git a/ubi-utils/src/nand2bin.c b/ubi-utils/src/nand2bin.c index a5e8bca..a9b68bd 100644 --- a/ubi-utils/src/nand2bin.c +++ b/ubi-utils/src/nand2bin.c @@ -20,7 +20,6 @@ * An utility to decompose NAND images and strip OOB off. Not yet finished ... */ #include -#include #include #include #include @@ -40,6 +39,9 @@ #define MAXPATH 1024 #define MIN(x,y) ((x)<(y)?(x):(y)) +extern char *optarg; +extern int optind; + struct args { const char *oob_file; const char *output_file; @@ -58,48 +60,29 @@ static struct args myargs = { .options = NULL, }; -static error_t parse_opt (int key, char *arg, struct argp_state *state); - -const char *argp_program_bug_address = PACKAGE_BUGREPORT; - static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\t" BUILD_OS" "BUILD_CPU" at "__DATE__" "__TIME__"\n" "\nSplit data and OOB.\n"; -static struct argp_option options[] = { - { .name = "pagesize", - .key = 'p', - .arg = "", - .flags = 0, - .doc = "NAND pagesize", - .group = OPTION_ARG_OPTIONAL }, - - { .name = "output", - .key = 'o', - .arg = "", - .flags = 0, - .doc = "Data output file", - .group = OPTION_ARG_OPTIONAL }, - - { .name = "oob", - .key = 'O', - .arg = "", - .flags = 0, - .doc = "OOB output file", - .group = OPTION_ARG_OPTIONAL }, - - { .name = NULL, .key = 0, .arg = NULL, .flags = 0, - .doc = NULL, .group = 0 }, -}; - -static struct argp argp = { - .options = options, - .parser = parse_opt, - .args_doc = "input.mif", - .doc = doc, - .children = NULL, - .help_filter = NULL, - .argp_domain = NULL, +static const char *optionsstr = +" -o, --output= Data output file\n" +" -O, --oob= OOB output file\n" +" -p, --pagesize= NAND pagesize\n" +" -?, --help Give this help list\n" +" --usage Give a short usage message\n"; + +static const char *usage = +"Usage: nand2bin [-?] [-o ] [-O ] [-p ]\n" +" [--output=] [--oob=] [--pagesize=] [--help]\n" +" [--usage] input.mif\n"; + +struct option long_options[] = { + { .name = "output", .has_arg = 1, .flag = NULL, .val = 'o' }, + { .name = "oob", .has_arg = 1, .flag = NULL, .val = 'O' }, + { .name = "pagesize", .has_arg = 1, .flag = NULL, .val = 'p' }, + { .name = "help", .has_arg = 0, .flag = NULL, .val = '?' }, + { .name = "usage", .has_arg = 0, .flag = NULL, .val = 0 }, + { NULL, 0, NULL, 0} }; /* @@ -137,52 +120,51 @@ uint32_t str_to_num(char *str) * Get the `input' argument from `argp_parse', which we know is a * pointer to our arguments structure. */ -static error_t -parse_opt(int key, char *arg, struct argp_state *state) +static int +parse_opt(int argc, char **argv, struct args *args) { - struct args *args = state->input; - - switch (key) { - case 'p': /* --pagesize */ - args->pagesize = str_to_num(arg); break; - - case 'o': /* --output= */ - args->output_file = arg; - break; - - case 'O': /* --oob= */ - args->output_file = arg; - break; - - case ARGP_KEY_NO_ARGS: - /* argp_usage(state); */ - break; - - case ARGP_KEY_ARG: - args->arg1 = arg; - /* Now we consume all the rest of the arguments. - `state->next' is the index in `state->argv' of the - next argument to be parsed, which is the first STRING - we're interested in, so we can just use - `&state->argv[state->next]' as the value for - arguments->strings. - - _In addition_, by setting `state->next' to the end - of the arguments, we can force argp to stop parsing here and - return. */ - - args->options = &state->argv[state->next]; - state->next = state->argc; - break; - - case ARGP_KEY_END: - /* argp_usage(state); */ - break; - - default: - return(ARGP_ERR_UNKNOWN); + while (1) { + int key; + + key = getopt_long(argc, argv, "o:O:p:?", long_options, NULL); + if (key == -1) + break; + + switch (key) { + case 'p': /* --pagesize */ + args->pagesize = str_to_num(optarg); + break; + + case 'o': /* --output= */ + args->output_file = optarg; + break; + + case 'O': /* --oob= */ + args->output_file = optarg; + break; + + case '?': /* help */ + printf("Usage: nand2bin [OPTION...] input.mif\n"); + printf("%s", doc); + printf("%s", optionsstr); + printf("\nReport bugs to %s\n", PACKAGE_BUGREPORT); + exit(0); + break; + + case 'V': + printf("%s\n", PACKAGE_VERSION); + exit(0); + break; + + default: + printf("%s", usage); + exit(-1); + } } + if (optind < argc) + args->arg1 = argv[optind++]; + return 0; } @@ -295,7 +277,7 @@ main(int argc, char *argv[]) { FILE *in, *bin, *oob; - argp_parse(&argp, argc, argv, ARGP_IN_ORDER, 0, &myargs); + parse_opt(argc, argv, &myargs); if (!myargs.arg1) { fprintf(stderr, "Please specify input file!\n"); -- cgit v1.2.3 From da59698ccf81a1df3a250edb81a91f1b8a3decf0 Mon Sep 17 00:00:00 2001 From: Frank Haverkamp Date: Mon, 11 Dec 2006 14:34:23 +0100 Subject: [MTD] UBI Utils: Tools should have individual version numbers The tools had a mixture of different version numbers. This is changed now. The internal change to move to remove glibc dependencies should be reflected by an increase of the version number, so that we can react if trouble is seen with the new code. Singed-off-by: Frank Haverkamp --- ubi-utils/src/bin2nand.c | 24 +++++++++++++++--------- ubi-utils/src/config.h | 4 ++-- ubi-utils/src/mkbootenv.c | 19 ++++++++++++------- ubi-utils/src/nand2bin.c | 12 +++++++++--- ubi-utils/src/pddcustomize.c | 22 +++++++++++++++------- ubi-utils/src/pfi2bin.c | 9 ++++++--- ubi-utils/src/pfiflash.c | 2 +- ubi-utils/src/ubigen.c | 35 +++++++++++++++++++++-------------- ubi-utils/src/ubimirror.c | 17 ++++++++++++----- ubi-utils/src/ubimkvol.c | 16 ++++++++++------ ubi-utils/src/ubirmvol.c | 11 +++++++---- ubi-utils/src/ubiupdatevol.c | 2 +- ubi-utils/src/unubi.c | 4 +++- 13 files changed, 114 insertions(+), 63 deletions(-) (limited to 'ubi-utils/src/nand2bin.c') diff --git a/ubi-utils/src/bin2nand.c b/ubi-utils/src/bin2nand.c index df838af..4bab1ad 100644 --- a/ubi-utils/src/bin2nand.c +++ b/ubi-utils/src/bin2nand.c @@ -22,10 +22,11 @@ * Create a flashable NAND image from a binary image * * History: - * 1.0: Initial release (tglx) - * 1.1: Understands hex and dec input parameters (tglx) - * 1.2: Generates separated OOB data, if needed. (oloh) - * 1.3: Padds data/oob to a given size. (oloh) + * 1.0 Initial release (tglx) + * 1.1 Understands hex and dec input parameters (tglx) + * 1.2 Generates separated OOB data, if needed. (oloh) + * 1.3 Padds data/oob to a given size. (oloh) + * 1.4 Removed argp because we want to use uClibc. */ #include @@ -44,6 +45,8 @@ #include "config.h" #include "nandecc.h" +#define PROGRAM_VERSION "1.4" + #define CHECK_ENDP(option, endp) do { \ if (*endp) { \ fprintf(stderr, \ @@ -65,7 +68,7 @@ typedef enum action_t { extern char *optarg; extern int optind; -static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\tBuilt on " +static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" "bin2nand - a tool for adding OOB information to a " @@ -153,11 +156,13 @@ parse_opt(int argc, char **argv, myargs *args) switch (key) { case 'p': /* pagesize */ - args->pagesize = (size_t) ustrtoull(optarg, &endp, 0); + args->pagesize = (size_t) + ustrtoull(optarg, &endp, 0); CHECK_ENDP("p", endp); break; case 'j': /* padding */ - args->padding = (size_t) ustrtoull(optarg, &endp, 0); + args->padding = (size_t) + ustrtoull(optarg, &endp, 0); CHECK_ENDP("j", endp); break; case 'o': /* output */ @@ -172,7 +177,7 @@ parse_opt(int argc, char **argv, myargs *args) exit(0); break; case 'V': - printf("%s\n", PACKAGE_VERSION); + printf("%s\n", PROGRAM_VERSION); exit(0); break; case 'c': @@ -187,7 +192,8 @@ parse_opt(int argc, char **argv, myargs *args) if (optind < argc) { args->fp_in = fopen(argv[optind++], "rb"); if ((args->fp_in) == NULL) { - err_quit("Cannot open file %s for input\n", argv[optind++]); + err_quit("Cannot open file %s for input\n", + argv[optind++]); } } diff --git a/ubi-utils/src/config.h b/ubi-utils/src/config.h index b5bbd5b..8c4dd54 100644 --- a/ubi-utils/src/config.h +++ b/ubi-utils/src/config.h @@ -20,8 +20,8 @@ * Author: Frank Haverkamp */ -#define PACKAGE_VERSION "1.1" -#define PACKAGE_BUGREPORT "haver@vnet.ibm.com, dedekind@linutronix.de, or tglx@linutronix.de" +#define PACKAGE_BUGREPORT \ + "haver@vnet.ibm.com, dedekind@linutronix.de, or tglx@linutronix.de" #define __unused __attribute__((unused)) diff --git a/ubi-utils/src/mkbootenv.c b/ubi-utils/src/mkbootenv.c index a556939..c05f4e2 100644 --- a/ubi-utils/src/mkbootenv.c +++ b/ubi-utils/src/mkbootenv.c @@ -18,6 +18,8 @@ * Author: Oliver Lohmann * * Create boot-parameter/pdd data from an ASCII-text input file. + * + * 1.2 Removed argp because we want to use uClibc. */ #include @@ -32,10 +34,12 @@ #include "bootenv.h" #include "error.h" +#define PROGRAM_VERSION "1.2" + extern char *optarg; extern int optind; -static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\tBuilt on " +static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" "mkbootenv - processes bootenv text files and convertes " @@ -91,19 +95,20 @@ parse_opt(int argc, char **argv, myargs *args) case 'o': args->fp_out = fopen(optarg, "wb"); if ((args->fp_out) == NULL) { - fprintf(stderr, - "Cannot open file %s for output\n", optarg); + fprintf(stderr, "Cannot open file %s " + "for output\n", optarg); exit(1); } break; case '?': /* help */ printf("%s", doc); printf("%s", optionsstr); - printf("\nReport bugs to %s\n", PACKAGE_BUGREPORT); + printf("\nReport bugs to %s\n", + PACKAGE_BUGREPORT); exit(0); break; case 'V': - printf("%s\n", PACKAGE_VERSION); + printf("%s\n", PROGRAM_VERSION); exit(0); break; default: @@ -115,8 +120,8 @@ parse_opt(int argc, char **argv, myargs *args) if (optind < argc) { args->fp_in = fopen(argv[optind++], "rb"); if ((args->fp_in) == NULL) { - fprintf(stderr, - "Cannot open file %s for input\n", argv[optind]); + fprintf(stderr, "Cannot open file %s for input\n", + argv[optind]); exit(1); } } diff --git a/ubi-utils/src/nand2bin.c b/ubi-utils/src/nand2bin.c index a9b68bd..34cce40 100644 --- a/ubi-utils/src/nand2bin.c +++ b/ubi-utils/src/nand2bin.c @@ -18,7 +18,10 @@ * Author: Frank Haverkamp * * An utility to decompose NAND images and strip OOB off. Not yet finished ... + * + * 1.2 Removed argp because we want to use uClibc. */ + #include #include #include @@ -36,6 +39,8 @@ #include "config.h" #include "nandecc.h" +#define PROGRAM_VERSION "1.2" + #define MAXPATH 1024 #define MIN(x,y) ((x)<(y)?(x):(y)) @@ -60,7 +65,7 @@ static struct args myargs = { .options = NULL, }; -static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\t" +static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\t" BUILD_OS" "BUILD_CPU" at "__DATE__" "__TIME__"\n" "\nSplit data and OOB.\n"; @@ -147,12 +152,13 @@ parse_opt(int argc, char **argv, struct args *args) printf("Usage: nand2bin [OPTION...] input.mif\n"); printf("%s", doc); printf("%s", optionsstr); - printf("\nReport bugs to %s\n", PACKAGE_BUGREPORT); + printf("\nReport bugs to %s\n", + PACKAGE_BUGREPORT); exit(0); break; case 'V': - printf("%s\n", PACKAGE_VERSION); + printf("%s\n", PROGRAM_VERSION); exit(0); break; diff --git a/ubi-utils/src/pddcustomize.c b/ubi-utils/src/pddcustomize.c index 5d1864a..5c2a5f0 100644 --- a/ubi-utils/src/pddcustomize.c +++ b/ubi-utils/src/pddcustomize.c @@ -23,6 +23,8 @@ * if the system is updated and one must be able to modify them when * the system has booted the first time. This tool is intended to do * PDD modification. + * + * 1.3 Removed argp because we want to use uClibc. */ #include @@ -41,6 +43,8 @@ #include "libubi.h" #include "ubimirror.h" +#define PROGRAM_VERSION "1.3" + typedef enum action_t { ACT_NORMAL = 0, ACT_LIST, @@ -59,7 +63,7 @@ typedef enum action_t { extern char *optarg; extern int optind; -static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\tBuilt on " +static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" "pddcustomize - customize bootenv and pdd values.\n"; @@ -160,7 +164,8 @@ parse_opt(int argc, char **argv, myargs *args) while (1) { int key; - key = getopt_long(argc, argv, "clbxs:i:o:?V", long_options, NULL); + key = getopt_long(argc, argv, "clbxs:i:o:?V", + long_options, NULL); if (key == -1) break; @@ -182,8 +187,9 @@ parse_opt(int argc, char **argv, myargs *args) args->side = get_update_side(optarg); if (args->side < 0) { err_msg("Unsupported seqnum: %d.\n" - "Supported seqnums are '0' and '1'\n", - args->side, optarg); + "Supported seqnums are " + "'0' and '1'\n", + args->side, optarg); ERR_ARGP; } break; @@ -194,14 +200,16 @@ parse_opt(int argc, char **argv, myargs *args) args->file_out = optarg; break; case '?': /* help */ - err_msg("Usage: pddcustomize.orig [OPTION...] [key=value] [...]"); + err_msg("Usage: pddcustomize.orig [OPTION...] " + "[key=value] [...]"); err_msg("%s", doc); err_msg("%s", optionsstr); - err_msg("\nReport bugs to %s", PACKAGE_BUGREPORT); + err_msg("\nReport bugs to %s", + PACKAGE_BUGREPORT); exit(0); break; case 'V': - err_msg("%s", PACKAGE_VERSION); + err_msg("%s", PROGRAM_VERSION); exit(0); break; default: diff --git a/ubi-utils/src/pfi2bin.c b/ubi-utils/src/pfi2bin.c index 044fa24..9265fd5 100644 --- a/ubi-utils/src/pfi2bin.c +++ b/ubi-utils/src/pfi2bin.c @@ -22,6 +22,8 @@ * chips in a manufacturing step where the flashes are written before * being soldered onto the hardware. For NAND images another step is * required to add the right OOB data to the binary image. + * + * 1.3 Removed argp because we want to use uClibc. */ #include @@ -42,7 +44,7 @@ #include "peb.h" #include "crc32.h" -#define PROGRAM_VERSION "1.2" +#define PROGRAM_VERSION "1.3" #define MAX_FNAME 255 #define DEFAULT_ERASE_COUNT 0 /* Hmmm.... Perhaps */ @@ -157,12 +159,13 @@ parse_opt(int argc, char **argv, myargs *args) printf("pfi2bin [OPTION...] pfifile\n"); printf("%s", doc); printf("%s", optionsstr); - printf("\nReport bugs to %s\n", PACKAGE_BUGREPORT); + printf("\nReport bugs to %s\n", + PACKAGE_BUGREPORT); exit(0); break; case 'V': - printf("%s\n", PACKAGE_VERSION); + printf("%s\n", PROGRAM_VERSION); exit(0); break; diff --git a/ubi-utils/src/pfiflash.c b/ubi-utils/src/pfiflash.c index 259a647..63487b9 100644 --- a/ubi-utils/src/pfiflash.c +++ b/ubi-utils/src/pfiflash.c @@ -193,7 +193,7 @@ parse_opt(int argc, char **argv, myargs *args) exit(0); break; case 'V': - err_msg("%s", PACKAGE_VERSION); + err_msg("%s", PROGRAM_VERSION); exit(0); break; default: diff --git a/ubi-utils/src/ubigen.c b/ubi-utils/src/ubigen.c index 226834f..877f469 100644 --- a/ubi-utils/src/ubigen.c +++ b/ubi-utils/src/ubigen.c @@ -21,6 +21,7 @@ * * 1.0 Initial version * 1.1 Different CRC32 start value + * 1.2 Removed argp because we want to use uClibc. */ #include @@ -34,6 +35,8 @@ #include "ubigen.h" #include "config.h" +#define PROGRAM_VERSION "1.2" + typedef enum action_t { ACT_NORMAL = 0x00000001, ACT_BROKEN_UPDATE = 0x00000002, @@ -42,7 +45,7 @@ typedef enum action_t { extern char *optarg; extern int optind; -static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\tBuilt on " +static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" "ubigen - a tool for adding UBI information to a binary input file.\n"; @@ -187,16 +190,16 @@ parse_opt(int argc, char **argv, myargs *args) case 'o': /* output */ args->fp_out = fopen(optarg, "wb"); if ((args->fp_out) == NULL) { - fprintf(stderr, "Cannot open file %s for output\n", - optarg); + fprintf(stderr, "Cannot open file %s " + "for output\n", optarg); exit(1); } break; case 'i': /* input */ args->fp_in = fopen(optarg, "rb"); if ((args->fp_in) == NULL) { - fprintf(stderr, "Cannot open file %s for input\n", - optarg); + fprintf(stderr, "Cannot open file %s " + "for input\n", optarg); exit(1); } break; @@ -205,23 +208,26 @@ parse_opt(int argc, char **argv, myargs *args) break; case 'B': /* eb_size */ - args->eb_size = (uint32_t) ustrtoul(optarg, &endp, 0); + args->eb_size = + (uint32_t)ustrtoul(optarg, &endp, 0); CHECK_ENDP("B", endp); break; case 'E': /* erasecount */ - args->ec = (uint64_t) strtoul(optarg, &endp, 0); + args->ec = (uint64_t)strtoul(optarg, &endp, 0); CHECK_ENDP("E", endp); break; case 'I': /* id */ - args->id = (uint16_t) strtoul(optarg, &endp, 0); + args->id = (uint16_t)strtoul(optarg, &endp, 0); CHECK_ENDP("I", endp); break; case 'T': /* type */ - args->type = (uint16_t) strtoul(optarg, &endp, 0); + args->type = + (uint16_t)strtoul(optarg, &endp, 0); CHECK_ENDP("T", endp); break; case 'X': /* versionnr */ - args->version = (uint8_t) strtoul(optarg, &endp, 0); + args->version = + (uint8_t)strtoul(optarg, &endp, 0); CHECK_ENDP("X", endp); break; case 'O': /* offset for volume hdr */ @@ -241,12 +247,13 @@ parse_opt(int argc, char **argv, myargs *args) fprintf(stderr, "Usage: ubigen [OPTION...]\n"); fprintf(stderr, "%s", doc); fprintf(stderr, "%s", optionsstr); - fprintf(stderr, "\nReport bugs to %s\n", PACKAGE_BUGREPORT); + fprintf(stderr, "\nReport bugs to %s\n", + PACKAGE_BUGREPORT); exit(0); break; case 'V': - fprintf(stderr, "%s\n", PACKAGE_VERSION); + fprintf(stderr, "%s\n", PROGRAM_VERSION); exit(0); break; @@ -260,8 +267,8 @@ parse_opt(int argc, char **argv, myargs *args) if (!args->fp_in) { args->fp_in = fopen(argv[optind++], "rb"); if ((args->fp_in) == NULL) { - fprintf(stderr, - "Cannot open file %s for input\n", argv[optind]); + fprintf(stderr, "Cannot open file %s for " + "input\n", argv[optind]); exit(1); } } diff --git a/ubi-utils/src/ubimirror.c b/ubi-utils/src/ubimirror.c index 1b1d0be..533a0ee 100644 --- a/ubi-utils/src/ubimirror.c +++ b/ubi-utils/src/ubimirror.c @@ -16,6 +16,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Author: Oliver Lohmann + * + * 1.2 Removed argp because we want to use uClibc. */ #include @@ -32,6 +34,8 @@ #include "example_ubi.h" #include "ubimirror.h" +#define PROGRAM_VERSION "1.2" + typedef enum action_t { ACT_NORMAL = 0, ACT_ARGP_ABORT, @@ -51,7 +55,7 @@ typedef enum action_t { extern char *optarg; extern int optind; -static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\tBuilt on " +static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" "ubimirror - mirrors ubi volumes.\n"; @@ -122,19 +126,22 @@ parse_opt(int argc, char **argv, myargs *args) args->side = get_update_side(optarg); if (args->side < 0) { err_msg("Unsupported seqnum: %s.\n" - "Supported seqnums are '0' and '1'\n", optarg); + "Supported seqnums are '0' " + "and '1'\n", optarg); ERR_ARGP; } break; case '?': /* help */ - err_msg("Usage: ubimirror [OPTION...] \n"); + err_msg("Usage: ubimirror [OPTION...] " + " \n"); err_msg("%s", doc); err_msg("%s", optionsstr); - err_msg("\nReport bugs to %s\n", PACKAGE_BUGREPORT); + err_msg("\nReport bugs to %s\n", + PACKAGE_BUGREPORT); exit(0); break; case 'V': - err_msg("%s", PACKAGE_VERSION); + err_msg("%s", PROGRAM_VERSION); exit(0); break; default: diff --git a/ubi-utils/src/ubimkvol.c b/ubi-utils/src/ubimkvol.c index 7d510eb..e878d70 100644 --- a/ubi-utils/src/ubimkvol.c +++ b/ubi-utils/src/ubimkvol.c @@ -26,6 +26,7 @@ * 1.1 Does not support erase blocks anymore. This is replaced by * the number of bytes. * 1.2 Reworked the user-interface to use argp. + * 1.3 Removed argp because we want to use uClibc. */ #include @@ -38,7 +39,7 @@ #include #include -#define PROGRAM_VERSION "1.2" +#define PROGRAM_VERSION "1.3" extern char *optarg; extern int optind; @@ -179,10 +180,12 @@ parse_opt(int argc, char **argv, struct args *args) break; case 'n': /* --volid= */ args->vol_id = strtoul(optarg, &endp, 0); - if (*endp != '\0' || endp == optarg || - (args->vol_id < 0 && args->vol_id != UBI_DYNAMIC_VOLUME)) { + if (*endp != '\0' || + endp == optarg || + (args->vol_id < 0 && + args->vol_id != UBI_DYNAMIC_VOLUME)) { fprintf(stderr, "Bad volume ID: " - "\"%s\"\n", optarg); + "\"%s\"\n", optarg); goto out; } break; @@ -199,12 +202,13 @@ parse_opt(int argc, char **argv, struct args *args) fprintf(stderr, "Usage: ubimkvol [OPTION...]\n"); fprintf(stderr, "%s", doc); fprintf(stderr, "%s", optionsstr); - fprintf(stderr, "\nReport bugs to %s\n", PACKAGE_BUGREPORT); + fprintf(stderr, "\nReport bugs to %s\n", + PACKAGE_BUGREPORT); exit(0); break; case 'V': - fprintf(stderr, "%s\n", PACKAGE_VERSION); + fprintf(stderr, "%s\n", PROGRAM_VERSION); exit(0); break; diff --git a/ubi-utils/src/ubirmvol.c b/ubi-utils/src/ubirmvol.c index 69e4d0e..04ec085 100644 --- a/ubi-utils/src/ubirmvol.c +++ b/ubi-utils/src/ubirmvol.c @@ -23,6 +23,7 @@ * Frank Haverkamp * * 1.1 Reworked the userinterface to use argp. + * 1.2 Removed argp because we want to use uClibc. */ #include @@ -35,7 +36,7 @@ #include #include -#define PROGRAM_VERSION "1.1" +#define PROGRAM_VERSION "1.2" extern char *optarg; extern int optind; @@ -123,7 +124,8 @@ parse_opt(int argc, char **argv, struct args *args) case 'n': /* --volid= */ args->vol_id = strtoul(optarg, &endp, 0); if (*endp != '\0' || endp == optarg || - (args->vol_id < 0 && args->vol_id != UBI_DYNAMIC_VOLUME)) { + (args->vol_id < 0 && + args->vol_id != UBI_DYNAMIC_VOLUME)) { fprintf(stderr, "Bad volume ID: " "\"%s\"\n", optarg); goto out; @@ -136,11 +138,12 @@ parse_opt(int argc, char **argv, struct args *args) fprintf(stderr, "Usage: ubirmvol [OPTION...]\n"); fprintf(stderr, "%s", doc); fprintf(stderr, "%s", optionsstr); - fprintf(stderr, "\nReport bugs to %s\n", PACKAGE_BUGREPORT); + fprintf(stderr, "\nReport bugs to %s\n", + PACKAGE_BUGREPORT); exit(0); break; case 'V': - fprintf(stderr, "%s\n", PACKAGE_VERSION); + fprintf(stderr, "%s\n", PROGRAM_VERSION); exit(0); break; default: diff --git a/ubi-utils/src/ubiupdatevol.c b/ubi-utils/src/ubiupdatevol.c index 753ad61..011d532 100644 --- a/ubi-utils/src/ubiupdatevol.c +++ b/ubi-utils/src/ubiupdatevol.c @@ -154,7 +154,7 @@ parse_opt(int argc, char **argv, struct args *args) break; case 'V': - fprintf(stderr, "%s\n", PACKAGE_VERSION); + fprintf(stderr, "%s\n", PROGRAM_VERSION); exit(0); break; diff --git a/ubi-utils/src/unubi.c b/ubi-utils/src/unubi.c index f8045d8..0f8945f 100644 --- a/ubi-utils/src/unubi.c +++ b/ubi-utils/src/unubi.c @@ -19,6 +19,8 @@ /* * Authors: Frank Haverkamp, haver@vnet.ibm.com * Drake Dowsett, dowsett@de.ibm.com + * + * 1.2 Removed argp because we want to use uClibc. */ /* @@ -51,7 +53,7 @@ #define EXEC "unubi" #define CONTACT "haver@vnet.ibm.com" -#define VERSION "0.9" +#define VERSION "1.0" extern char *optarg; extern int optind; -- cgit v1.2.3 From d45b87985d5371b2e47458ee0666f7979d5a8c21 Mon Sep 17 00:00:00 2001 From: Josh Boyer Date: Tue, 12 Dec 2006 09:22:48 +0100 Subject: [PATCH] Minor ubi utils cleanups Remove getopt extern declarations Minor whitespace cleanups Remove incorrect program names that snuck in during getopt rewrite Change comments to match reality Signed-off-by: Josh Boyer Acked-by: Frank Haverkamp --- ubi-utils/src/bin2nand.c | 6 ++---- ubi-utils/src/mkbootenv.c | 6 ++---- ubi-utils/src/nand2bin.c | 14 +++++--------- ubi-utils/src/pddcustomize.c | 10 ++++------ ubi-utils/src/pfi2bin.c | 8 +++----- ubi-utils/src/pfiflash.c | 8 +++----- ubi-utils/src/ubigen.c | 8 +++----- ubi-utils/src/ubimirror.c | 6 ++---- ubi-utils/src/ubimkvol.c | 35 ++++++++++++++++++----------------- ubi-utils/src/ubirmvol.c | 25 ++++++++++++------------- ubi-utils/src/ubiupdatevol.c | 7 ++----- ubi-utils/src/unubi.c | 19 +++++++------------ 12 files changed, 63 insertions(+), 89 deletions(-) (limited to 'ubi-utils/src/nand2bin.c') diff --git a/ubi-utils/src/bin2nand.c b/ubi-utils/src/bin2nand.c index 4bab1ad..20fc90a 100644 --- a/ubi-utils/src/bin2nand.c +++ b/ubi-utils/src/bin2nand.c @@ -27,6 +27,7 @@ * 1.2 Generates separated OOB data, if needed. (oloh) * 1.3 Padds data/oob to a given size. (oloh) * 1.4 Removed argp because we want to use uClibc. + * 1.5 Minor cleanup */ #include @@ -45,7 +46,7 @@ #include "config.h" #include "nandecc.h" -#define PROGRAM_VERSION "1.4" +#define PROGRAM_VERSION "1.5" #define CHECK_ENDP(option, endp) do { \ if (*endp) { \ @@ -65,9 +66,6 @@ typedef enum action_t { #define PADDING 0 /* 0 means, do not adjust anything */ #define BUFSIZE 4096 -extern char *optarg; -extern int optind; - static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" diff --git a/ubi-utils/src/mkbootenv.c b/ubi-utils/src/mkbootenv.c index c05f4e2..4a8cc6a 100644 --- a/ubi-utils/src/mkbootenv.c +++ b/ubi-utils/src/mkbootenv.c @@ -20,6 +20,7 @@ * Create boot-parameter/pdd data from an ASCII-text input file. * * 1.2 Removed argp because we want to use uClibc. + * 1.3 Minor cleanup */ #include @@ -34,10 +35,7 @@ #include "bootenv.h" #include "error.h" -#define PROGRAM_VERSION "1.2" - -extern char *optarg; -extern int optind; +#define PROGRAM_VERSION "1.3" static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" diff --git a/ubi-utils/src/nand2bin.c b/ubi-utils/src/nand2bin.c index 34cce40..636ee6f 100644 --- a/ubi-utils/src/nand2bin.c +++ b/ubi-utils/src/nand2bin.c @@ -20,6 +20,7 @@ * An utility to decompose NAND images and strip OOB off. Not yet finished ... * * 1.2 Removed argp because we want to use uClibc. + * 1.3 Minor cleanup */ #include @@ -39,14 +40,11 @@ #include "config.h" #include "nandecc.h" -#define PROGRAM_VERSION "1.2" +#define PROGRAM_VERSION "1.3" #define MAXPATH 1024 #define MIN(x,y) ((x)<(y)?(x):(y)) -extern char *optarg; -extern int optind; - struct args { const char *oob_file; const char *output_file; @@ -116,14 +114,12 @@ uint32_t str_to_num(char *str) /* * @brief Parse the arguments passed into the test case. * - * @param key The parameter. - * @param arg Argument passed to parameter. - * @param state Location to put information on parameters. + * @param argc The number of arguments + * @param argv The argument list + * @param args Pointer to program args structure * * @return error * - * Get the `input' argument from `argp_parse', which we know is a - * pointer to our arguments structure. */ static int parse_opt(int argc, char **argv, struct args *args) diff --git a/ubi-utils/src/pddcustomize.c b/ubi-utils/src/pddcustomize.c index 5c2a5f0..764f2e7 100644 --- a/ubi-utils/src/pddcustomize.c +++ b/ubi-utils/src/pddcustomize.c @@ -25,6 +25,7 @@ * PDD modification. * * 1.3 Removed argp because we want to use uClibc. + * 1.4 Minor cleanups */ #include @@ -43,7 +44,7 @@ #include "libubi.h" #include "ubimirror.h" -#define PROGRAM_VERSION "1.3" +#define PROGRAM_VERSION "1.4" typedef enum action_t { ACT_NORMAL = 0, @@ -60,9 +61,6 @@ typedef enum action_t { args->action = ACT_ARGP_ERR; \ } while (0) -extern char *optarg; -extern int optind; - static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" @@ -81,7 +79,7 @@ static const char *optionsstr = " -V, --version Print program version\n"; static const char *usage = -"Usage: pddcustomize.orig [-bclx?V] [-i ] [-o ] [-s ]\n" +"Usage: pddcustomize [-bclx?V] [-i ] [-o ] [-s ]\n" " [--both] [--copyright] [--input=] [--list]\n" " [--output=] [--side=] [--host] [--help] [--usage]\n" " [--version] [key=value] [...]\n"; @@ -200,7 +198,7 @@ parse_opt(int argc, char **argv, myargs *args) args->file_out = optarg; break; case '?': /* help */ - err_msg("Usage: pddcustomize.orig [OPTION...] " + err_msg("Usage: pddcustomize [OPTION...] " "[key=value] [...]"); err_msg("%s", doc); err_msg("%s", optionsstr); diff --git a/ubi-utils/src/pfi2bin.c b/ubi-utils/src/pfi2bin.c index 9265fd5..57c4ea5 100644 --- a/ubi-utils/src/pfi2bin.c +++ b/ubi-utils/src/pfi2bin.c @@ -24,6 +24,7 @@ * required to add the right OOB data to the binary image. * * 1.3 Removed argp because we want to use uClibc. + * 1.4 Minor cleanups */ #include @@ -44,7 +45,7 @@ #include "peb.h" #include "crc32.h" -#define PROGRAM_VERSION "1.3" +#define PROGRAM_VERSION "1.4" #define MAX_FNAME 255 #define DEFAULT_ERASE_COUNT 0 /* Hmmm.... Perhaps */ @@ -52,9 +53,6 @@ #define MIN(a,b) ((a) < (b) ? (a) : (b)) -extern char *optarg; -extern int optind; - static uint32_t crc32_table[256]; static char err_buf[ERR_BUF_SIZE]; @@ -92,7 +90,7 @@ static const char *optionsstr = " -V, --version Print program version\n"; static const char *usage = -"Usage: pfi2bin.orig [-cv?V] [-j pdd-file] [-o filename] [--copyright]\n" +"Usage: pfi2bin [-cv?V] [-j pdd-file] [-o filename] [--copyright]\n" " [--verbose] [--platform=pdd-file] [--output=filename] [--help]\n" " [--usage] [--version] pfifile\n"; diff --git a/ubi-utils/src/pfiflash.c b/ubi-utils/src/pfiflash.c index 63487b9..0b0da56 100644 --- a/ubi-utils/src/pfiflash.c +++ b/ubi-utils/src/pfiflash.c @@ -25,6 +25,7 @@ * 1.1 fixed output to stderr and stdout in logfile mode. * 1.2 updated. * 1.3 removed argp parsing to be able to use uClib. + * 1.4 Minor cleanups */ #include @@ -41,10 +42,7 @@ #include "error.h" #include "config.h" -#define PROGRAM_VERSION "1.3" - -extern char *optarg; -extern int optind; +#define PROGRAM_VERSION "1.4" static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" @@ -70,7 +68,7 @@ static const char *optionsstr = " -V, --version Print program version\n"; static const char *usage = -"Usage: pfiflash.orig [-cvC?V] [-l ] [-p ] [-r ] [-s ]\n" +"Usage: pfiflash [-cvC?V] [-l ] [-p ] [-r ] [-s ]\n" " [--copyright] [--logfile=] [--verbose] [--complete]\n" " [--pdd-update=] [--raw-flash=] [--side=]\n" " [--help] [--usage] [--version] [pfifile]\n"; diff --git a/ubi-utils/src/ubigen.c b/ubi-utils/src/ubigen.c index 877f469..d99ba2d 100644 --- a/ubi-utils/src/ubigen.c +++ b/ubi-utils/src/ubigen.c @@ -22,6 +22,7 @@ * 1.0 Initial version * 1.1 Different CRC32 start value * 1.2 Removed argp because we want to use uClibc. + * 1.3 Minor cleanups */ #include @@ -35,16 +36,13 @@ #include "ubigen.h" #include "config.h" -#define PROGRAM_VERSION "1.2" +#define PROGRAM_VERSION "1.3" typedef enum action_t { ACT_NORMAL = 0x00000001, ACT_BROKEN_UPDATE = 0x00000002, } action_t; -extern char *optarg; -extern int optind; - static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" @@ -85,7 +83,7 @@ static const char *optionsstr = " -V, --version Print program version\n"; static const char *usage = -"Usage: ubigen.orig [-cdv?V] [-A ] [-B ] [-E ] [-I ]\n" +"Usage: ubigen [-cdv?V] [-A ] [-B ] [-E ] [-I ]\n" " [-O ] [-T ] [-X ] [-i ] [-o ]\n" " [-U ] [--copyright] [--debug] [--verbose] [--alignment=]\n" " [--blocksize=] [--erasecount=] [--id=]\n" diff --git a/ubi-utils/src/ubimirror.c b/ubi-utils/src/ubimirror.c index 533a0ee..eeedb3a 100644 --- a/ubi-utils/src/ubimirror.c +++ b/ubi-utils/src/ubimirror.c @@ -18,6 +18,7 @@ * Author: Oliver Lohmann * * 1.2 Removed argp because we want to use uClibc. + * 1.3 Minor cleanups */ #include @@ -34,7 +35,7 @@ #include "example_ubi.h" #include "ubimirror.h" -#define PROGRAM_VERSION "1.2" +#define PROGRAM_VERSION "1.3" typedef enum action_t { ACT_NORMAL = 0, @@ -52,9 +53,6 @@ typedef enum action_t { #define VOL_ARGS_MAX 2 -extern char *optarg; -extern int optind; - static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" diff --git a/ubi-utils/src/ubimkvol.c b/ubi-utils/src/ubimkvol.c index e878d70..879dcb6 100644 --- a/ubi-utils/src/ubimkvol.c +++ b/ubi-utils/src/ubimkvol.c @@ -27,6 +27,7 @@ * the number of bytes. * 1.2 Reworked the user-interface to use argp. * 1.3 Removed argp because we want to use uClibc. + * 1.4 Minor cleanups */ #include @@ -39,10 +40,7 @@ #include #include -#define PROGRAM_VERSION "1.3" - -extern char *optarg; -extern int optind; +#define PROGRAM_VERSION "1.4" /* * The variables below are set by command line arguments. @@ -114,14 +112,12 @@ struct option long_options[] = { /* * @brief Parse the arguments passed into the test case. * - * @param key The parameter. - * @param arg Argument passed to parameter. - * @param state Location to put information on parameters. + * @param argc The number of arguments + * @param argv The list of arguments + * @param args Pointer to argument structure * * @return error * - * Get the `input' argument from `argp_parse', which we know is a - * pointer to our arguments structure. */ static int parse_opt(int argc, char **argv, struct args *args) @@ -142,16 +138,18 @@ parse_opt(int argc, char **argv, struct args *args) else if (!strcmp(optarg, "static")) args->vol_type = UBI_STATIC_VOLUME; else { - fprintf(stderr, "Bad volume type: \"%s\"\n", - optarg); + fprintf(stderr, + "Bad volume type: \"%s\"\n", + optarg); goto out; } break; case 's': args->bytes = strtoull(optarg, &endp, 0); if (endp == optarg || args->bytes < 0) { - fprintf(stderr, "Bad volume size: \"%s\"\n", - optarg); + fprintf(stderr, + "Bad volume size: \"%s\"\n", + optarg); goto out; } if (endp != '\0') { @@ -172,9 +170,11 @@ parse_opt(int argc, char **argv, struct args *args) break; case 'd': /* --devn= */ args->devn = strtoul(optarg, &endp, 0); - if (*endp != '\0' || endp == optarg || args->devn < 0) { - fprintf(stderr, "Bad UBI device number: " - "\"%s\"\n", optarg); + if (*endp != '\0' || endp == optarg || + args->devn < 0) { + fprintf(stderr, + "Bad UBI device number: " + "\"%s\"\n", optarg); goto out; } break; @@ -199,7 +199,8 @@ parse_opt(int argc, char **argv, struct args *args) goto out; case '?': /* help */ - fprintf(stderr, "Usage: ubimkvol [OPTION...]\n"); + fprintf(stderr, + "Usage: ubimkvol [OPTION...]\n"); fprintf(stderr, "%s", doc); fprintf(stderr, "%s", optionsstr); fprintf(stderr, "\nReport bugs to %s\n", diff --git a/ubi-utils/src/ubirmvol.c b/ubi-utils/src/ubirmvol.c index 04ec085..f458e8a 100644 --- a/ubi-utils/src/ubirmvol.c +++ b/ubi-utils/src/ubirmvol.c @@ -24,6 +24,7 @@ * * 1.1 Reworked the userinterface to use argp. * 1.2 Removed argp because we want to use uClibc. + * 1.3 Minor cleanups */ #include @@ -36,10 +37,7 @@ #include #include -#define PROGRAM_VERSION "1.2" - -extern char *optarg; -extern int optind; +#define PROGRAM_VERSION "1.3" /* * The below variables are set by command line options. @@ -91,14 +89,12 @@ struct option long_options[] = { /* * @brief Parse the arguments passed into the test case. * - * @param key The parameter. - * @param arg Argument passed to parameter. - * @param state Location to put information on parameters. + * @param argc The number of arguments + * @param argv The list of arguments + * @param args Pointer to argument structure * * @return error * - * Get the `input' argument from `argp_parse', which we know is a - * pointer to our arguments structure. */ static int parse_opt(int argc, char **argv, struct args *args) @@ -115,9 +111,11 @@ parse_opt(int argc, char **argv, struct args *args) switch (key) { case 'd': /* --devn= */ args->devn = strtoul(optarg, &endp, 0); - if (*endp != '\0' || endp == optarg || args->devn < 0) { - fprintf(stderr, "Bad UBI device number: " - "\"%s\"\n", optarg); + if (*endp != '\0' || endp == optarg || + args->devn < 0) { + fprintf(stderr, + "Bad UBI device number: " + "\"%s\"\n", optarg); goto out; } break; @@ -135,7 +133,8 @@ parse_opt(int argc, char **argv, struct args *args) fprintf(stderr, "Parameter is missing\n"); goto out; case '?': /* help */ - fprintf(stderr, "Usage: ubirmvol [OPTION...]\n"); + fprintf(stderr, + "Usage: ubirmvol [OPTION...]\n"); fprintf(stderr, "%s", doc); fprintf(stderr, "%s", optionsstr); fprintf(stderr, "\nReport bugs to %s\n", diff --git a/ubi-utils/src/ubiupdatevol.c b/ubi-utils/src/ubiupdatevol.c index 011d532..b3c4bf1 100644 --- a/ubi-utils/src/ubiupdatevol.c +++ b/ubi-utils/src/ubiupdatevol.c @@ -24,6 +24,7 @@ * * 1.0 Reworked the userinterface to use argp. * 1.1 Removed argp parsing because we want to use uClib. + * 1.2 Minor cleanups */ #include @@ -42,16 +43,12 @@ #include #include -#define PROGRAM_VERSION "1.1" +#define PROGRAM_VERSION "1.2" #define MAXPATH 1024 #define BUFSIZE 128 * 1024 #define MIN(x,y) ((x)<(y)?(x):(y)) -/* FIXME is this not covered by including getopt.h? */ -extern char *optarg; -extern int optind; - struct args { int devn; int vol_id; diff --git a/ubi-utils/src/unubi.c b/ubi-utils/src/unubi.c index 0f8945f..cade1e1 100644 --- a/ubi-utils/src/unubi.c +++ b/ubi-utils/src/unubi.c @@ -21,6 +21,7 @@ * Drake Dowsett, dowsett@de.ibm.com * * 1.2 Removed argp because we want to use uClibc. + * 1.3 Minor cleanups */ /* @@ -53,10 +54,7 @@ #define EXEC "unubi" #define CONTACT "haver@vnet.ibm.com" -#define VERSION "1.0" - -extern char *optarg; -extern int optind; +#define VERSION "1.3" static char doc[] = "\nVersion: " VERSION "\n\t" BUILD_OS" "BUILD_CPU" at "__DATE__" "__TIME__"\n" @@ -177,12 +175,6 @@ str_to_num(char *str) return num; } - -/** - * parses the arguments passed into the program - * get the input argument from argp_parse, which we know is a - * pointer to our arguments structure; - **/ static int parse_opt(int argc, char **argv, struct args *args) { @@ -225,10 +217,13 @@ parse_opt(int argc, char **argv, struct args *args) args->vol_split = SPLIT_RAW; break; case '?': /* help */ - fprintf(stderr, "Usage: unubi [OPTION...] image-file\n"); + fprintf(stderr, + "Usage: unubi [OPTION...] " + "image-file\n"); fprintf(stderr, "%s", doc); fprintf(stderr, "%s", optionsstr); - fprintf(stderr, "\nReport bugs to %s\n", CONTACT); + fprintf(stderr, + "\nReport bugs to %s\n", CONTACT); exit(0); break; case 'J': -- cgit v1.2.3 From 9fe86e65fb6bd77a02955d07d6f336ace4984e2d Mon Sep 17 00:00:00 2001 From: Josh Boyer Date: Mon, 12 Feb 2007 20:41:17 -0600 Subject: Fix several issues when compiling for 64bit systems Signed-off-by: Josh Boyer --- ubi-utils/src/hashmap.c | 2 +- ubi-utils/src/libubi.c | 4 ++-- ubi-utils/src/nand2bin.c | 2 +- ubi-utils/src/pfi.c | 2 +- ubi-utils/src/reader.c | 7 ++++--- ubi-utils/src/unubi.c | 2 +- ubi-utils/src/unubi_analyze.c | 20 ++++++++++---------- 7 files changed, 20 insertions(+), 19 deletions(-) (limited to 'ubi-utils/src/nand2bin.c') diff --git a/ubi-utils/src/hashmap.c b/ubi-utils/src/hashmap.c index 250f71f..3511d56 100644 --- a/ubi-utils/src/hashmap.c +++ b/ubi-utils/src/hashmap.c @@ -323,7 +323,7 @@ hashmap_dump(hashmap_t map) for(i = 0; i < map->maxsize; i++) { if (map->data[i] != NULL) { - printf("[%d]: ", i); + printf("[%zd]: ", i); print_all(map->data[i]); } } diff --git a/ubi-utils/src/libubi.c b/ubi-utils/src/libubi.c index 979f157..7cb74bf 100644 --- a/ubi-utils/src/libubi.c +++ b/ubi-utils/src/libubi.c @@ -698,8 +698,8 @@ ubi_vol_update(int vol_fd, unsigned long long bytes) err = ioctl(vol_fd, UBI_IOCVOLUP, &bytes); if (err) { ubi_err("%s failure calling update ioctl\n" - " IOCTL(%08x) err=%d errno=%d\n", - __func__, UBI_IOCVOLUP, err, errno); + " IOCTL(%08lx) err=%d errno=%d\n", + __func__, (long unsigned int)UBI_IOCVOLUP, err, errno); } return err; } diff --git a/ubi-utils/src/nand2bin.c b/ubi-utils/src/nand2bin.c index 636ee6f..b8e4ea3 100644 --- a/ubi-utils/src/nand2bin.c +++ b/ubi-utils/src/nand2bin.c @@ -203,7 +203,7 @@ process_page(uint8_t* buf, uint8_t *oobbuf, size_t pagesize) case 2048: oobsize = 64; eccpoi = 64 / 2; break; case 512: oobsize = 16; eccpoi = 16 / 2; break; default: - fprintf(stderr, "Unsupported page size: %d\n", pagesize); + fprintf(stderr, "Unsupported page size: %zd\n", pagesize); return -EINVAL; } memset(oobbuf, 0xff, oobsize); diff --git a/ubi-utils/src/pfi.c b/ubi-utils/src/pfi.c index 7b57559..fa835e2 100644 --- a/ubi-utils/src/pfi.c +++ b/ubi-utils/src/pfi.c @@ -253,7 +253,7 @@ int pfi_header_setvalue (pfi_header head, { int key_id = find_key_by_name(key); - if ((uint32_t)value == (uint32_t)NULL) + if (value == NULL) return PFI_EINSUFF; if ((key_id < 0) || (key_id >= num_keys)) diff --git a/ubi-utils/src/reader.c b/ubi-utils/src/reader.c index 975caa1..7935a15 100644 --- a/ubi-utils/src/reader.c +++ b/ubi-utils/src/reader.c @@ -178,7 +178,8 @@ read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi __unused, pfi_raw_t* pfi_raw, } rc = bootenv_list_to_num_vector(raw_start_list, - &(res->starts_size), &(res->starts)); + (void *) &(res->starts_size), + &(res->starts)); if (rc != 0) { EBUF_PFI("Cannot create numeric value array: %s", tmp_str); goto err; @@ -246,7 +247,7 @@ read_pfi_ubi(pfi_header pfi_hd, FILE* fp_pfi __unused, pfi_ubi_t* pfi_ubi, goto err; } - rc = bootenv_list_to_num_vector(ubi_id_list, &(res->ids_size), + rc = bootenv_list_to_num_vector(ubi_id_list, (void *) &(res->ids_size), &(res->ids)); if (rc != 0) { EBUF_PFI("Cannot create numeric value array: %s", tmp_str); @@ -298,7 +299,7 @@ read_pfi_ubi(pfi_header pfi_hd, FILE* fp_pfi __unused, pfi_ubi_t* pfi_ubi, EBUF_PFI("Cannot translate PFI value: %s", tmp_str); goto err; } - rc = bootenv_list_to_vector(ubi_name_list, &(res->names_size), + rc = bootenv_list_to_vector(ubi_name_list, (void *) &(res->names_size), &(tmp_names)); if (rc != 0) { EBUF_PFI("Cannot create string array: %s", tmp_str); diff --git a/ubi-utils/src/unubi.c b/ubi-utils/src/unubi.c index cade1e1..811a6db 100644 --- a/ubi-utils/src/unubi.c +++ b/ubi-utils/src/unubi.c @@ -102,7 +102,7 @@ static const char *usage = #define FN_INVAL "%s/eb%04u%s" /* invalid eraseblock */ #define FN_NSURE "%s/eb%04u_%03u_%03u_%03x%s" /* unsure eraseblock */ #define FN_VALID "%s/eb%04u_%03u_%03u_%03x%s" /* valid eraseblock */ -#define FN_VOLSP "%s/vol%03u_%03u_%03u_%04u" /* split volume */ +#define FN_VOLSP "%s/vol%03u_%03u_%03u_%04zu" /* split volume */ #define FN_VOLWH "%s/volume%03u" /* whole volume */ static uint32_t crc32_table[256]; diff --git a/ubi-utils/src/unubi_analyze.c b/ubi-utils/src/unubi_analyze.c index 2e94ca9..6009fc0 100644 --- a/ubi-utils/src/unubi_analyze.c +++ b/ubi-utils/src/unubi_analyze.c @@ -167,9 +167,9 @@ unubi_analyze_ec_hdr(eb_info_t first, const char *path) (crc != ubi32_to_cpu(cur->outer.hdr_crc))) fprintf(fpdata, "# "); - fprintf(fpdata, "%u %llu %llu", count, - ubi64_to_cpu(cur->outer.ec), - erase_counts[count]); + fprintf(fpdata, "%zu %llu %llu", count, + (unsigned long long) ubi64_to_cpu(cur->outer.ec), + (unsigned long long) erase_counts[count]); if (ubi32_to_cpu(cur->outer.magic) != UBI_EC_HDR_MAGIC) fprintf(fpdata, " ## bad magic: %08x", @@ -198,7 +198,7 @@ unubi_analyze_ec_hdr(eb_info_t first, const char *path) if ((count % EC_X_INT) == 0) { if (count > 0) fprintf(fpplot, ", "); - fprintf(fpplot, "%d", count); + fprintf(fpplot, "%zd", count); } cur = cur->next; @@ -207,9 +207,9 @@ unubi_analyze_ec_hdr(eb_info_t first, const char *path) fprintf(fpplot, ")\n"); fprintf(fpplot, "set ylabel \"erase count\"\n"); - fprintf(fpplot, "set xrange [-1:%u]\n", eraseblocks + 1); + fprintf(fpplot, "set xrange [-1:%zu]\n", eraseblocks + 1); fprintf(fpplot, "# set yrange [-1:%llu]\n", - erase_counts[eraseblocks - 1] + 1); + (unsigned long long) erase_counts[eraseblocks - 1] + 1); fprintf(fpplot, "plot \"%s\" u 1:2 t \"unsorted: %s\" with boxes\n", FN_EH_DATA, FN_EH_DATA); fprintf(fpplot, "# replot \"%s\" u 1:3 t \"sorted: %s\" with lines\n", @@ -299,7 +299,7 @@ unubi_analyze_vid_hdr(eb_info_t *head, const char *path) if ((y1 == -1) || (y2 == -1)) return -1; - fprintf(fpdata, "%u %u %u %u %u %u %u\n", + fprintf(fpdata, "%zu %u %u %u %u %u %u\n", count, ubi32_to_cpu(cur->inner.vol_id), ubi32_to_cpu(cur->inner.lnum), @@ -325,10 +325,10 @@ unubi_analyze_vid_hdr(eb_info_t *head, const char *path) fprintf(fpplot, ", "); if (step != ubi32_to_cpu(cur->inner.vol_id)) { step = ubi32_to_cpu(cur->inner.vol_id); - fprintf(fpplot, "\"%d\" %d 0", step, count); + fprintf(fpplot, "\"%zd\" %zd 0", step, count); } else - fprintf(fpplot, "\"%d\" %d 1", + fprintf(fpplot, "\"%d\" %zd 1", ubi32_to_cpu(cur->inner.lnum), count); cur = cur->next; count++; @@ -384,7 +384,7 @@ unubi_analyze_vid_hdr(eb_info_t *head, const char *path) y1 = norm_index(leb_versions[breadth - 1], leb_versions, breadth); y2 = norm_index(data_sizes[breadth - 1], data_sizes, breadth); - fprintf(fpplot, "set xrange [-1:%u]\n", count + 1); + fprintf(fpplot, "set xrange [-1:%zu]\n", count + 1); fprintf(fpplot, "set yrange [-1:%u]\n", y1 + 1); fprintf(fpplot, "set y2range [-1:%u]\n", y2 + 1); fprintf(fpplot, "plot \"%s\" u 1:4 t \"leb version: %s\" " -- cgit v1.2.3