aboutsummaryrefslogtreecommitdiff
path: root/ubi-utils/src
diff options
context:
space:
mode:
authorFrank Haverkamp <haver@vnet.ibm.com>2006-12-11 14:34:23 +0100
committerFrank Haverkamp <haver@vnet.ibm.com>2006-12-11 14:34:23 +0100
commit1fea122705bfecebf38e57774762663b7cd913d2 (patch)
treec4ec84f253d1dda879ca08a45997e9d8f93cb191 /ubi-utils/src
parent084fb764956460b5e67865b6072ea9cc4a2b5af9 (diff)
[MTD] UBI Utils: Fix pfiflash
Various little fixes including some whitespace fixups. Signed-off-by: Frank Haverkamp <haver@vnet.ibm.com>
Diffstat (limited to 'ubi-utils/src')
-rw-r--r--ubi-utils/src/libpfiflash.c15
-rw-r--r--ubi-utils/src/pfiflash.c21
2 files changed, 25 insertions, 11 deletions
diff --git a/ubi-utils/src/libpfiflash.c b/ubi-utils/src/libpfiflash.c
index dd55203..0be1f2c 100644
--- a/ubi-utils/src/libpfiflash.c
+++ b/ubi-utils/src/libpfiflash.c
@@ -593,6 +593,8 @@ process_raw_volumes(FILE* pfi, list_t pfi_raws, const char* rawdev,
rc = 0;
+ pfi_data = NULL;
+
log_msg("[ rawupdate dev=%s", rawdev);
crc = UBI_CRC32_INIT;
@@ -603,6 +605,8 @@ process_raw_volumes(FILE* pfi, list_t pfi_raws, const char* rawdev,
pfi_raw_t r = (pfi_raw_t)i;
/* read in pfi data */
+ if (pfi_data != NULL)
+ free(pfi_data);
pfi_data = malloc(r->data_size * sizeof(char));
for (j = 0; j < r->data_size; j++) {
int c = fgetc(pfi);
@@ -629,7 +633,7 @@ process_raw_volumes(FILE* pfi, list_t pfi_raws, const char* rawdev,
/* open device */
mtd = fopen(rawdev, "r+");
if (mtd == NULL) {
- rc = PFIFLASH_ERR_MTD_OPEN;
+ rc = -PFIFLASH_ERR_MTD_OPEN;
EBUF(PFIFLASH_ERRSTR[-rc], rawdev);
goto err;
}
@@ -642,11 +646,12 @@ process_raw_volumes(FILE* pfi, list_t pfi_raws, const char* rawdev,
fclose(mtd);
rc = -PFIFLASH_ERR_EOF;
EBUF(PFIFLASH_ERRSTR[-rc]);
- return rc;
+ goto err;
}
if ((char)c != pfi_data[k]) {
fclose(mtd);
- return -1;
+ rc = -1;
+ goto err;
}
}
}
@@ -659,6 +664,8 @@ process_raw_volumes(FILE* pfi, list_t pfi_raws, const char* rawdev,
}
err:
+ if (pfi_data != NULL)
+ free(pfi_data);
return rc;
}
@@ -692,7 +699,7 @@ erase_unmapped_ubi_volumes(int devno, list_t pfi_ubis,
foreach(u, ptr, pfi_ubis) {
/* iterate over each vol_id */
for(i = 0; i < u->ids_size; i++) {
- if (u->ids[i] > PFI_UBI_MAX_VOLUMES) {
+ if (u->ids[i] >= PFI_UBI_MAX_VOLUMES) {
rc = -PFIFLASH_ERR_UBI_VID_OOB;
EBUF(PFIFLASH_ERRSTR[-rc], u->ids[i]);
goto err;
diff --git a/ubi-utils/src/pfiflash.c b/ubi-utils/src/pfiflash.c
index c654be9..259a647 100644
--- a/ubi-utils/src/pfiflash.c
+++ b/ubi-utils/src/pfiflash.c
@@ -23,6 +23,8 @@
* update using PFI files.
*
* 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.
*/
#include <unistd.h>
@@ -39,7 +41,7 @@
#include "error.h"
#include "config.h"
-#define PROGRAM_VERSION "1.2"
+#define PROGRAM_VERSION "1.3"
extern char *optarg;
extern int optind;
@@ -141,7 +143,8 @@ parse_opt(int argc, char **argv, myargs *args)
while (1) {
int key;
- key = getopt_long(argc, argv, "cl:vCp:r:s:?V", long_options, NULL);
+ key = getopt_long(argc, argv, "cl:vCp:r:s:?V",
+ long_options, NULL);
if (key == -1)
break;
@@ -165,15 +168,17 @@ parse_opt(int argc, char **argv, myargs *args)
args->pdd_handling = get_pdd_handling(optarg);
if ((int)args->pdd_handling < 0) {
err_quit("Unknown PDD handling: %s.\n"
- "Please use either 'keep', 'merge' or"
- "'overwrite'.\n'");
+ "Please use either "
+ "'keep', 'merge' or"
+ "'overwrite'.\n'");
}
break;
case 's':
args->seqnum = get_update_seqnum(optarg);
if (args->seqnum < 0) {
err_quit("Unsupported side: %s.\n"
- "Supported sides are '0' and '1'\n", optarg);
+ "Supported sides are '0' "
+ "and '1'\n", optarg);
}
break;
case 'r':
@@ -183,7 +188,8 @@ parse_opt(int argc, char **argv, myargs *args)
err_msg("Usage: pfiflash [OPTION...] [pfifile]");
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':
@@ -200,7 +206,8 @@ parse_opt(int argc, char **argv, myargs *args)
if (optind < argc) {
args->fp_in = fopen(argv[optind++], "r");
if ((args->fp_in) == NULL) {
- err_sys("Cannot open PFI file %s for input", argv[optind]);
+ err_sys("Cannot open PFI file %s for input",
+ argv[optind]);
}
}