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/pfi2bin.c | 678 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 678 insertions(+) create mode 100644 ubi-utils/src/pfi2bin.c (limited to 'ubi-utils/src/pfi2bin.c') diff --git a/ubi-utils/src/pfi2bin.c b/ubi-utils/src/pfi2bin.c new file mode 100644 index 0000000..6536c19 --- /dev/null +++ b/ubi-utils/src/pfi2bin.c @@ -0,0 +1,678 @@ +/* + * 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: Oliver Lohmann + * + * Convert a PFI file (partial flash image) into a plain binary file. + * This tool can be used to prepare the data to be burned into flash + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "config.h" +#include "list.h" +#include "error.h" +#include "reader.h" +#include "peb.h" +#include "crc32.h" + +#define MAX_FNAME 255 +#define DEFAULT_ERASE_COUNT 0 /* Hmmm.... Perhaps */ +#define ERR_BUF_SIZE 1024 + +#define MIN(a,b) ((a) < (b) ? (a) : (b)) + +static uint32_t crc32_table[256]; +static char err_buf[ERR_BUF_SIZE]; + +/* + * Data used to buffer raw blocks which have to be + * located at a specific point inside the generated RAW file + */ + +typedef enum action_t { + ACT_NOTHING = 0x00000000, + ACT_RAW = 0x00000001, +} action_t; + +static const char copyright [] __attribute__((unused)) = + "Licensed Materials - Property of IBM\n" + "IBM Flexible Support Processor Licensed Material\n" + "(c) Copyright IBM Corp 2006 All Rights Reserved.\n" + "US Government Users Restricted Rights - Use, duplication\n" + "or disclosure restricted by GSA ADP Schedule Contract\n" + "with IBM Corp."; + +static error_t parse_opt (int key, char *arg, struct argp_state *state); + +const char *argp_program_version = PACKAGE_VERSION; +const char *argp_program_bug_address = PACKAGE_BUGREPORT; +static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\tBuilt on " + BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" + "\n" + "pfi2bin - a tool to convert PFI files into binary images.\n"; + +static struct argp_option options[] = { + /* COMMON */ + { name: NULL, key: 0, arg: NULL, flags: 0, + doc: "Common settings:", + group: OPTION_ARG_OPTIONAL}, + + { name: "verbose", key: 'v', arg: NULL, flags: 0, + doc: "Print more information.", + group: OPTION_ARG_OPTIONAL }, + + { name: "copyright", key: 'c', arg: NULL, flags: 0, + group: OPTION_ARG_OPTIONAL }, + + + /* INPUT */ + { name: NULL, key: 0, arg: NULL, flags: 0, + doc: "Input:", + group: 4}, + + { name: "platform", key: 'j', arg: "pdd-file", flags: 0, + doc: "PDD information which contains the card settings.", + group: 4 }, + + /* OUTPUT */ + { name: NULL, key: 0, arg: NULL, flags: 0, + doc: "Output:", + group: 5}, + + { name: "output", key: 'o', arg: "filename", flags: 0, + doc: "Outputfile, default: stdout.", + group: 5 }, + + { name: NULL, key: 0, arg: NULL, flags: 0, doc: NULL, group: 0 }, +}; + +typedef struct io { + FILE* fp_pdd; /* a FilePointer to the PDD data */ + FILE* fp_pfi; /* a FilePointer to the PFI input stream */ + FILE* fp_out; /* a FilePointer to the output stream */ +} *io_t; + +typedef struct myargs { + /* common settings */ + action_t action; + int verbose; + const char *f_in_pfi; + const char *f_in_pdd; + const char *f_out; + + /* special stuff needed to get additional arguments */ + char *arg1; + char **options; /* [STRING...] */ +} myargs; + +static struct argp argp = { + options: options, + parser: parse_opt, + args_doc: "pfifile", + doc: doc, + children: NULL, + help_filter: NULL, + argp_domain: NULL, +}; + +static error_t +parse_opt(int key, char *arg, struct argp_state *state) +{ + myargs *args = state->input; + + switch (key) { + /* common settings */ + case 'v': /* --verbose= */ + args->verbose = 1; + break; + + case 'c': /* --copyright */ + fprintf(stderr, "%s\n", copyright); + exit(0); + break; + + case 'j': /* --platform */ + args->f_in_pdd = arg; + break; + + case 'o': /* --output */ + args->f_out = arg; + break; + + case ARGP_KEY_ARG: + args->f_in_pfi = arg; + /* args->arg1 = arg; */ + args->options = &state->argv[state->next]; + state->next = state->argc; + break; + + case ARGP_KEY_END: + if (args->action == ACT_NOTHING) { + argp_usage(state); + exit(1); + } + break; + + default: + return(ARGP_ERR_UNKNOWN); + } + + return 0; +} + + +static size_t +byte_to_blk(size_t byte, size_t blk_size) +{ + return (byte % blk_size) == 0 + ? byte / blk_size + : byte / blk_size + 1; +} + + + + +/** + * @precondition IO: File stream points to first byte of RAW data. + * @postcondition IO: File stream points to first byte of next + * or EOF. + */ +static int +memorize_raw_eb(pfi_raw_t pfi_raw, pdd_data_t pdd, list_t *raw_pebs, + io_t io) +{ + int rc = 0; + uint32_t i; + + size_t read, to_read, eb_num; + size_t bytes_left; + list_t pebs = *raw_pebs; + peb_t peb = NULL; + + long old_file_pos = ftell(io->fp_pfi); + for (i = 0; i < pfi_raw->starts_size; i++) { + bytes_left = pfi_raw->data_size; + rc = fseek(io->fp_pfi, old_file_pos, SEEK_SET); + if (rc != 0) + goto err; + + eb_num = byte_to_blk(pfi_raw->starts[i], pdd->eb_size); + while (bytes_left) { + to_read = MIN(bytes_left, pdd->eb_size); + rc = peb_new(eb_num++, pdd->eb_size, &peb); + if (rc != 0) + goto err; + read = fread(peb->data, 1, to_read, io->fp_pfi); + if (read != to_read) { + rc = -EIO; + goto err; + } + pebs = append_elem(peb, pebs); + bytes_left -= read; + } + + } + *raw_pebs = pebs; + return 0; +err: + pebs = remove_all((free_func_t)&peb_free, pebs); + return rc; +} + +static int +convert_ubi_volume(pfi_ubi_t ubi, pdd_data_t pdd, list_t raw_pebs, + struct ubi_vol_tbl_record *vol_tab, + size_t *ebs_written, io_t io) +{ + int rc = 0; + uint32_t i, j; + peb_t raw_peb; + peb_t cmp_peb; + ubi_info_t u; + size_t leb_total = 0; + uint8_t vol_type; + + switch (ubi->type) { + case pfi_ubi_static: + vol_type = UBI_VID_STATIC; break; + case pfi_ubi_dynamic: + vol_type = UBI_VID_DYNAMIC; break; + default: + vol_type = UBI_VID_DYNAMIC; + } + + rc = peb_new(0, 0, &cmp_peb); + if (rc != 0) + goto err; + + long old_file_pos = ftell(io->fp_pfi); + for (i = 0; i < ubi->ids_size; i++) { + rc = fseek(io->fp_pfi, old_file_pos, SEEK_SET); + if (rc != 0) + goto err; + rc = ubigen_create(&u, ubi->ids[i], vol_type, + pdd->eb_size, DEFAULT_ERASE_COUNT, + ubi->alignment, UBI_VERSION, + pdd->vid_hdr_offset, 0, ubi->data_size, + io->fp_pfi, io->fp_out); + if (rc != 0) + goto err; + + rc = ubigen_get_leb_total(u, &leb_total); + if (rc != 0) + goto err; + + j = 0; + while(j < leb_total) { + cmp_peb->num = *ebs_written; + raw_peb = is_in((cmp_func_t)peb_cmp, cmp_peb, + raw_pebs); + if (raw_peb) { + rc = peb_write(io->fp_out, raw_peb); + } + else { + rc = ubigen_write_leb(u, NO_ERROR); + j++; + } + if (rc != 0) + goto err; + (*ebs_written)++; + } + /* memorize volume table entry */ + rc = ubigen_set_lvol_rec(u, ubi->size, + ubi->names[i], + (void*) &vol_tab[ubi->ids[i]]); + if (rc != 0) + goto err; + ubigen_destroy(&u); + } + + peb_free(&cmp_peb); + return 0; + +err: + peb_free(&cmp_peb); + ubigen_destroy(&u); + return rc; +} + + +static FILE* +my_fmemopen (void *buf, size_t size, const char *opentype) +{ + FILE* f; + + assert(strcmp(opentype, "r") == 0); + + f = tmpfile(); + fwrite(buf, 1, size, f); + rewind(f); + + return f; +} + +/** + * @brief Builds a UBI volume table from a volume entry list. + * @return 0 On success. + * else Error. + */ +static int +write_ubi_volume_table(pdd_data_t pdd, list_t raw_pebs, + struct ubi_vol_tbl_record *vol_tab, size_t vol_tab_size, + size_t *ebs_written, io_t io) +{ + int rc = 0; + ubi_info_t u; + peb_t raw_peb; + peb_t cmp_peb; + size_t leb_size, leb_total, j = 0; + uint8_t *ptr = NULL; + FILE* fp_leb = NULL; + + rc = peb_new(0, 0, &cmp_peb); + if (rc != 0) + goto err; + + /* @FIXME: Artem creates one volume with 2 LEBs. + * IMO 2 volumes would be more convenient. In order + * to get 2 reserved LEBs from ubigen, I have to + * introduce this stupid mechanism. Until no final + * decision of the VTAB structure is made... Good enough. + */ + rc = ubigen_create(&u, UBI_LAYOUT_VOL_ID, UBI_VID_DYNAMIC, + pdd->eb_size, DEFAULT_ERASE_COUNT, + 1, UBI_VERSION, + pdd->vid_hdr_offset, UBI_COMPAT_REJECT, + vol_tab_size, stdin, io->fp_out); + /* @FIXME stdin for fp_in is a hack */ + if (rc != 0) + goto err; + rc = ubigen_get_leb_size(u, &leb_size); + if (rc != 0) + goto err; + ubigen_destroy(&u); + + ptr = (uint8_t*) malloc(leb_size * sizeof(uint8_t)); + if (ptr == NULL) + goto err; + memset(ptr, 0xff, leb_size); + memcpy(ptr, vol_tab, vol_tab_size); + fp_leb = my_fmemopen(ptr, leb_size, "r"); + + rc = ubigen_create(&u, UBI_LAYOUT_VOL_ID, UBI_VID_DYNAMIC, + pdd->eb_size, DEFAULT_ERASE_COUNT, + 1, UBI_VERSION, pdd->vid_hdr_offset, + UBI_COMPAT_REJECT, leb_size * UBI_LAYOUT_VOLUME_EBS, + fp_leb, io->fp_out); + if (rc != 0) + goto err; + rc = ubigen_get_leb_total(u, &leb_total); + if (rc != 0) + goto err; + + long old_file_pos = ftell(fp_leb); + while(j < leb_total) { + rc = fseek(fp_leb, old_file_pos, SEEK_SET); + if (rc != 0) + goto err; + + cmp_peb->num = *ebs_written; + raw_peb = is_in((cmp_func_t)peb_cmp, cmp_peb, + raw_pebs); + if (raw_peb) { + rc = peb_write(io->fp_out, raw_peb); + } + else { + rc = ubigen_write_leb(u, NO_ERROR); + j++; + } + + if (rc != 0) + goto err; + (*ebs_written)++; + } + +err: + free(ptr); + peb_free(&cmp_peb); + ubigen_destroy(&u); + fclose(fp_leb); + return rc; +} + +static int +write_remaining_raw_ebs(pdd_data_t pdd, list_t raw_blocks, size_t *ebs_written, + FILE* fp_out) +{ + int rc = 0; + uint32_t j, delta; + list_t ptr; + peb_t empty_eb, peb; + + /* create an empty 0xff EB (for padding) */ + rc = peb_new(0, pdd->eb_size, &empty_eb); + + foreach(peb, ptr, raw_blocks) { + if (peb->num < *ebs_written) { + continue; /* omit blocks which + are already passed */ + } + + if (peb->num < *ebs_written) { + err_msg("eb_num: %d\n", peb->num); + err_msg("Bug: This should never happen. %d %s", + __LINE__, __FILE__); + goto err; + } + + delta = peb->num - *ebs_written; + if (((delta + *ebs_written) * pdd->eb_size) > pdd->flash_size) { + err_msg("RAW block outside of flash_size."); + goto err; + } + for (j = 0; j < delta; j++) { + rc = peb_write(fp_out, empty_eb); + if (rc != 0) + goto err; + (*ebs_written)++; + } + rc = peb_write(fp_out, peb); + if (rc != 0) + goto err; + (*ebs_written)++; + } + +err: + peb_free(&empty_eb); + return rc; +} + +static int +init_vol_tab(struct ubi_vol_tbl_record **vol_tab, size_t *vol_tab_size) +{ + uint32_t crc; + size_t i; + struct ubi_vol_tbl_record* res = NULL; + + *vol_tab_size = UBI_MAX_VOLUMES * UBI_VTBL_RECORD_SIZE; + + res = (struct ubi_vol_tbl_record*) calloc(1, *vol_tab_size); + if (vol_tab == NULL) { + return -ENOMEM; + } + + for (i = 0; i < UBI_MAX_VOLUMES; i++) { + crc = clc_crc32(crc32_table, UBI_CRC32_INIT, + &(res[i]), UBI_VTBL_RECORD_SIZE_CRC); + res[i].crc = cpu_to_ubi32(crc); + } + + *vol_tab = res; + return 0; +} + +static int +create_raw(io_t io) +{ + int rc = 0; + size_t ebs_written = 0; /* eraseblocks written already... */ + size_t vol_tab_size; + list_t ptr; + + list_t pfi_raws = mk_empty(); /* list of raw sections from a pfi */ + list_t pfi_ubis = mk_empty(); /* list of ubi sections from a pfi */ + list_t raw_pebs = mk_empty(); /* list of raw eraseblocks */ + + struct ubi_vol_tbl_record *vol_tab = NULL; + pdd_data_t pdd = NULL; + + rc = init_vol_tab (&vol_tab, &vol_tab_size); + if (rc != 0) { + err_msg("Cannot initialize volume table."); + goto err; + } + + rc = read_pdd_data(io->fp_pdd, &pdd, + err_buf, ERR_BUF_SIZE); + if (rc != 0) { + err_msg("Cannot read necessary pdd_data: %s rc: %d", + err_buf, rc); + goto err; + } + + rc = read_pfi_headers(&pfi_raws, &pfi_ubis, io->fp_pfi, + err_buf, ERR_BUF_SIZE); + if (rc != 0) { + err_msg("Cannot read pfi header: %s rc: %d", + err_buf, rc); + goto err; + } + + pfi_raw_t pfi_raw; + foreach(pfi_raw, ptr, pfi_raws) { + rc = memorize_raw_eb(pfi_raw, pdd, &raw_pebs, + io); + if (rc != 0) { + err_msg("Cannot create raw_block in mem. rc: %d\n", + rc); + goto err; + } + } + + pfi_ubi_t pfi_ubi; + foreach(pfi_ubi, ptr, pfi_ubis) { + rc = convert_ubi_volume(pfi_ubi, pdd, raw_pebs, + vol_tab, &ebs_written, io); + if (rc != 0) { + err_msg("Cannot convert UBI volume. rc: %d\n", rc); + goto err; + } + } + + rc = write_ubi_volume_table(pdd, raw_pebs, vol_tab, vol_tab_size, + &ebs_written, io); + if (rc != 0) { + err_msg("Cannot write UBI volume table. rc: %d\n", rc); + goto err; + } + + rc = write_remaining_raw_ebs(pdd, raw_pebs, &ebs_written, io->fp_out); + if (rc != 0) + goto err; + + if (io->fp_out != stdout) + info_msg("Physical eraseblocks written: %8d\n", ebs_written); +err: + free(vol_tab); + pfi_raws = remove_all((free_func_t)&free_pfi_raw, pfi_raws); + pfi_ubis = remove_all((free_func_t)&free_pfi_ubi, pfi_ubis); + raw_pebs = remove_all((free_func_t)&peb_free, raw_pebs); + free_pdd_data(&pdd); + return rc; +} + + +/* ------------------------------------------------------------------------- */ +static void +open_io_handle(myargs *args, io_t io) +{ + /* set PDD input */ + io->fp_pdd = fopen(args->f_in_pdd, "r"); + if (io->fp_pdd == NULL) { + err_sys("Cannot open: %s", args->f_in_pdd); + } + + /* set PFI input */ + io->fp_pfi = fopen(args->f_in_pfi, "r"); + if (io->fp_pfi == NULL) { + err_sys("Cannot open PFI input file: %s", args->f_in_pfi); + } + + /* set output prefix */ + if (strcmp(args->f_out,"") == 0) + io->fp_out = stdout; + else { + io->fp_out = fopen(args->f_out, "wb"); + if (io->fp_out == NULL) { + err_sys("Cannot open output file: %s", args->f_out); + } + } +} + +static void +close_io_handle(io_t io) +{ + if (fclose(io->fp_pdd) != 0) { + err_sys("Cannot close PDD file."); + } + if (fclose(io->fp_pfi) != 0) { + err_sys("Cannot close PFI file."); + } + if (io->fp_out != stdout) { + if (fclose(io->fp_out) != 0) { + err_sys("Cannot close output file."); + } + } + + io->fp_pdd = NULL; + io->fp_pfi = NULL; + io->fp_out = NULL; +} + +int +main(int argc, char *argv[]) +{ + int rc = 0; + + ubigen_init(); + init_crc32_table(crc32_table); + + struct io io = {NULL, NULL, NULL}; + myargs args = { + .action = ACT_RAW, + .verbose = 0, + + .f_in_pfi = "", + .f_in_pdd = "", + .f_out = "", + + /* arguments */ + .arg1 = NULL, + .options = NULL, + }; + + /* parse arguments */ + argp_parse(&argp, argc, argv, ARGP_IN_ORDER, 0, &args); + + if (strcmp(args.f_in_pfi, "") == 0) { + err_quit("No PFI input file specified!"); + } + + if (strcmp(args.f_in_pdd, "") == 0) { + err_quit("No PDD input file specified!"); + } + + open_io_handle(&args, &io); + + info_msg("[ Creating RAW..."); + rc = create_raw(&io); + if (rc != 0) { + err_msg("Creating RAW failed."); + goto err; + } + +err: + close_io_handle(&io); + if (rc != 0) { + remove(args.f_out); + } + + return rc; +} -- cgit v1.2.3 From 02e51e7e0b4c50d900d3a246b2bce73df3a191ee Mon Sep 17 00:00:00 2001 From: Frank Haverkamp Date: Mon, 10 Jul 2006 15:47:05 +0200 Subject: [MTD] UBI: Fixed 16 KiB blocksize problem. --- ubi-utils/src/pfi2bin.c | 20 +++++++++++++++++--- ubi-utils/src/reader.c | 35 +++++++++++++++++++++++------------ ubi-utils/src/reader.h | 1 + 3 files changed, 41 insertions(+), 15 deletions(-) (limited to 'ubi-utils/src/pfi2bin.c') diff --git a/ubi-utils/src/pfi2bin.c b/ubi-utils/src/pfi2bin.c index 6536c19..4c25faf 100644 --- a/ubi-utils/src/pfi2bin.c +++ b/ubi-utils/src/pfi2bin.c @@ -42,6 +42,8 @@ #include "peb.h" #include "crc32.h" +#define PROGRAM_VERSION "1.2" + #define MAX_FNAME 255 #define DEFAULT_ERASE_COUNT 0 /* Hmmm.... Perhaps */ #define ERR_BUF_SIZE 1024 @@ -71,9 +73,9 @@ static const char copyright [] __attribute__((unused)) = static error_t parse_opt (int key, char *arg, struct argp_state *state); -const char *argp_program_version = PACKAGE_VERSION; +const char *argp_program_version = PROGRAM_VERSION; const char *argp_program_bug_address = PACKAGE_BUGREPORT; -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" "pfi2bin - a tool to convert PFI files into binary images.\n"; @@ -355,6 +357,8 @@ write_ubi_volume_table(pdd_data_t pdd, list_t raw_pebs, size_t leb_size, leb_total, j = 0; uint8_t *ptr = NULL; FILE* fp_leb = NULL; + int vt_slots; + size_t vol_tab_size_limit; rc = peb_new(0, 0, &cmp_peb); if (rc != 0) @@ -379,11 +383,21 @@ write_ubi_volume_table(pdd_data_t pdd, list_t raw_pebs, goto err; ubigen_destroy(&u); + /* + * The number of supported volumes is restricted by the eraseblock size + * and by the UBI_MAX_VOLUMES constant. + */ + vt_slots = leb_size / UBI_VTBL_RECORD_SIZE; + if (vt_slots > UBI_MAX_VOLUMES) + vt_slots = UBI_MAX_VOLUMES; + vol_tab_size_limit = vt_slots * UBI_VTBL_RECORD_SIZE; + ptr = (uint8_t*) malloc(leb_size * sizeof(uint8_t)); if (ptr == NULL) goto err; + memset(ptr, 0xff, leb_size); - memcpy(ptr, vol_tab, vol_tab_size); + memcpy(ptr, vol_tab, vol_tab_size_limit); fp_leb = my_fmemopen(ptr, leb_size, "r"); rc = ubigen_create(&u, UBI_LAYOUT_VOL_ID, UBI_VID_DYNAMIC, diff --git a/ubi-utils/src/reader.c b/ubi-utils/src/reader.c index e4a8ceb..5de06d5 100644 --- a/ubi-utils/src/reader.c +++ b/ubi-utils/src/reader.c @@ -34,8 +34,9 @@ #include "reader.h" /* @FIXME hard coded offsets right now - get them from Artem? */ -#define NAND_DEFAULT_VID_HDR_OFF 1984 -#define NOR_DEFAULT_VID_HDR_OFF 64 +#define NAND2048_DEFAULT_VID_HDR_OFF 1984 +#define NAND512_DEFAULT_VID_HDR_OFF 448 +#define NOR_DEFAULT_VID_HDR_OFF 64 #define EBUF_PFI(fmt...) \ do { int i = snprintf(err_buf, err_buf_size, "%s\n", label); \ @@ -74,8 +75,27 @@ read_pdd_data(FILE* fp_pdd, pdd_data_t* pdd_data, } if (strcmp(value, "NAND") == 0) { + + rc = bootenv_get_num(pdd, "flash_page_size", + &(res->flash_page_size)); + if (rc != 0) { + EBUF("Cannot read 'flash_page_size' from pdd."); + goto err; + } res->flash_type = NAND_FLASH; - res->vid_hdr_offset = NAND_DEFAULT_VID_HDR_OFF; + + switch (res->flash_page_size) { + case 512: + res->vid_hdr_offset = NAND512_DEFAULT_VID_HDR_OFF; + break; + case 2048: + res->vid_hdr_offset = NAND2048_DEFAULT_VID_HDR_OFF; + break; + default: + EBUF("Unsupported 'flash_page_size' %d.", + res->flash_page_size); + goto err; + } } else if (strcmp(value, "NOR") == 0){ res->flash_type = NOR_FLASH; @@ -113,11 +133,6 @@ read_pdd_data(FILE* fp_pdd, pdd_data_t* pdd_data, return rc; } -/** - * FIXME enhance flasing raw PFI content e.g. IPLs for NAND and NOR. - * Here is one of the only places where the flash type and its special - * handling is exposed to the users. - */ int read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi __unused, pfi_raw_t* pfi_raw, const char* label, char* err_buf, size_t err_buf_size) @@ -175,10 +190,6 @@ read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi __unused, pfi_raw_t* pfi_raw, return rc; } -/** - * FIXME Enhance reading raw PFI sections, e.g. IPL. See comment at - * write_pfi_ubi. - */ int read_pfi_ubi(pfi_header pfi_hd, FILE* fp_pfi __unused, pfi_ubi_t* pfi_ubi, const char *label, char* err_buf, size_t err_buf_size) diff --git a/ubi-utils/src/reader.h b/ubi-utils/src/reader.h index 93c15e3..d00fa17 100644 --- a/ubi-utils/src/reader.h +++ b/ubi-utils/src/reader.h @@ -40,6 +40,7 @@ typedef struct pfi_ubi *pfi_ubi_t; struct pdd_data { uint32_t flash_size; + uint32_t flash_page_size; uint32_t eb_size; uint32_t vid_hdr_offset; flash_type_t flash_type; -- cgit v1.2.3 From c61aca05ac6fe2dba46a133c7c72aec8f7e3ae5b Mon Sep 17 00:00:00 2001 From: Josh Boyer Date: Tue, 5 Dec 2006 15:56:29 -0600 Subject: [PATCH] Try 2: Remove bogus copyright statement Signed-off-by: Josh Boyer Signed-off-by: Frank Haverkamp --- ubi-utils/src/pfi2bin.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'ubi-utils/src/pfi2bin.c') diff --git a/ubi-utils/src/pfi2bin.c b/ubi-utils/src/pfi2bin.c index 4c25faf..ec09a4d 100644 --- a/ubi-utils/src/pfi2bin.c +++ b/ubi-utils/src/pfi2bin.c @@ -64,12 +64,7 @@ typedef enum action_t { } action_t; static const char copyright [] __attribute__((unused)) = - "Licensed Materials - Property of IBM\n" - "IBM Flexible Support Processor Licensed Material\n" - "(c) Copyright IBM Corp 2006 All Rights Reserved.\n" - "US Government Users Restricted Rights - Use, duplication\n" - "or disclosure restricted by GSA ADP Schedule Contract\n" - "with IBM Corp."; + "(c) Copyright IBM Corp 2006\n"; static error_t parse_opt (int key, char *arg, struct argp_state *state); -- cgit v1.2.3 From 6d6841c32370763e585edb52465ad2eb65354f7d Mon Sep 17 00:00:00 2001 From: Josh Boyer Date: Mon, 11 Dec 2006 14:34:22 +0100 Subject: [PATCH 5/13] Convert pfi2bin to use getopt option parsing Signed-off-by: Josh Boyer Acked-by: Frank Haverkamp --- ubi-utils/src/pfi2bin.c | 168 +++++++++++++++++++++++------------------------- 1 file changed, 81 insertions(+), 87 deletions(-) (limited to 'ubi-utils/src/pfi2bin.c') diff --git a/ubi-utils/src/pfi2bin.c b/ubi-utils/src/pfi2bin.c index ec09a4d..044fa24 100644 --- a/ubi-utils/src/pfi2bin.c +++ b/ubi-utils/src/pfi2bin.c @@ -28,9 +28,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -50,6 +50,9 @@ #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]; @@ -66,48 +69,40 @@ typedef enum action_t { static const char copyright [] __attribute__((unused)) = "(c) Copyright IBM Corp 2006\n"; -static error_t parse_opt (int key, char *arg, struct argp_state *state); - -const char *argp_program_version = PROGRAM_VERSION; -const char *argp_program_bug_address = PACKAGE_BUGREPORT; static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" "pfi2bin - a tool to convert PFI files into binary images.\n"; -static struct argp_option options[] = { - /* COMMON */ - { name: NULL, key: 0, arg: NULL, flags: 0, - doc: "Common settings:", - group: OPTION_ARG_OPTIONAL}, - - { name: "verbose", key: 'v', arg: NULL, flags: 0, - doc: "Print more information.", - group: OPTION_ARG_OPTIONAL }, - - { name: "copyright", key: 'c', arg: NULL, flags: 0, - group: OPTION_ARG_OPTIONAL }, - - - /* INPUT */ - { name: NULL, key: 0, arg: NULL, flags: 0, - doc: "Input:", - group: 4}, - - { name: "platform", key: 'j', arg: "pdd-file", flags: 0, - doc: "PDD information which contains the card settings.", - group: 4 }, - - /* OUTPUT */ - { name: NULL, key: 0, arg: NULL, flags: 0, - doc: "Output:", - group: 5}, - - { name: "output", key: 'o', arg: "filename", flags: 0, - doc: "Outputfile, default: stdout.", - group: 5 }, - - { name: NULL, key: 0, arg: NULL, flags: 0, doc: NULL, group: 0 }, +static const char *optionsstr = +" Common settings:\n" +" -c, --copyright\n" +" -v, --verbose Print more information.\n" +"\n" +" Input:\n" +" -j, --platform=pdd-file PDD information which contains the card settings.\n" +"\n" +" Output:\n" +" -o, --output=filename Outputfile, default: stdout.\n" +"\n" +" -?, --help Give this help list\n" +" --usage Give a short usage message\n" +" -V, --version Print program version\n"; + +static const char *usage = +"Usage: pfi2bin.orig [-cv?V] [-j pdd-file] [-o filename] [--copyright]\n" +" [--verbose] [--platform=pdd-file] [--output=filename] [--help]\n" +" [--usage] [--version] pfifile\n"; + +struct option long_options[] = { + { .name = "copyright", .has_arg = 0, .flag = NULL, .val = 'c' }, + { .name = "verbose", .has_arg = 0, .flag = NULL, .val = 'v' }, + { .name = "platform", .has_arg = 1, .flag = NULL, .val = 'j' }, + { .name = "output", .has_arg = 1, .flag = NULL, .val = 'o' }, + { .name = "help", .has_arg = 0, .flag = NULL, .val = '?' }, + { .name = "usage", .has_arg = 0, .flag = NULL, .val = 0 }, + { .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' }, + { NULL, 0, NULL, 0} }; typedef struct io { @@ -129,58 +124,57 @@ typedef struct myargs { char **options; /* [STRING...] */ } myargs; -static struct argp argp = { - options: options, - parser: parse_opt, - args_doc: "pfifile", - doc: doc, - children: NULL, - help_filter: NULL, - argp_domain: NULL, -}; - -static error_t -parse_opt(int key, char *arg, struct argp_state *state) +static int +parse_opt(int argc, char **argv, myargs *args) { - myargs *args = state->input; - - switch (key) { - /* common settings */ - case 'v': /* --verbose= */ - args->verbose = 1; - break; - - case 'c': /* --copyright */ - fprintf(stderr, "%s\n", copyright); - exit(0); - break; - - case 'j': /* --platform */ - args->f_in_pdd = arg; - break; - - case 'o': /* --output */ - args->f_out = arg; - break; - - case ARGP_KEY_ARG: - args->f_in_pfi = arg; - /* args->arg1 = arg; */ - args->options = &state->argv[state->next]; - state->next = state->argc; - break; - - case ARGP_KEY_END: - if (args->action == ACT_NOTHING) { - argp_usage(state); - exit(1); + while (1) { + int key; + + key = getopt_long(argc, argv, "cvj:o:?V", long_options, NULL); + if (key == -1) + break; + + switch (key) { + /* common settings */ + case 'v': /* --verbose= */ + args->verbose = 1; + break; + + case 'c': /* --copyright */ + fprintf(stderr, "%s\n", copyright); + exit(0); + break; + + case 'j': /* --platform */ + args->f_in_pdd = optarg; + break; + + case 'o': /* --output */ + args->f_out = optarg; + break; + + case '?': /* help */ + printf("pfi2bin [OPTION...] pfifile\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); } - break; - - default: - return(ARGP_ERR_UNKNOWN); } + if (optind < argc) + args->f_in_pfi = argv[optind++]; + return 0; } @@ -658,7 +652,7 @@ main(int argc, char *argv[]) }; /* parse arguments */ - argp_parse(&argp, argc, argv, ARGP_IN_ORDER, 0, &args); + parse_opt(argc, argv, &args); if (strcmp(args.f_in_pfi, "") == 0) { err_quit("No PFI input file specified!"); -- 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/pfi2bin.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/pfi2bin.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