rc = 0;
+ pfi_data = NULL;
+
log_msg("[ rawupdate dev=%s", rawdev);
crc = UBI_CRC32_INIT;
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);
/* 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;
}
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;
}
}
}
}
err:
+ if (pfi_data != NULL)
+ free(pfi_data);
return rc;
}
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;
* 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>
#include "error.h"
#include "config.h"
-#define PROGRAM_VERSION "1.2"
+#define PROGRAM_VERSION "1.3"
extern char *optarg;
extern int optind;
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;
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':
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':
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]);
}
}