Browse Source

Fix bug, dont ask.

master
heck 2 years ago
parent
commit
16fca81b3b
  1. 46
      src/ch341eeprom.c

46
src/ch341eeprom.c

@ -48,13 +48,20 @@ int main(int argc, char **argv) {
static char usage_msg[] =
"Usage:\n" \
" fvflash [options] [operation] filename\n" \
" writes filename into fv1 (must be in bin format)\n\n"
"operation:\n"\
" default operation is write fv1\n"\
" -e, --erase erase fv1 (fill with 0xff)\n" \
" -r, --read <filename> read fv1 and save image to filename\n\n"
"options:\n"\
" -h, --help display this text\n" \
" -d, --debug debug output\n" \
" -s, --size size of EEPROM {24c32|24c64} default=24c32\n" \
" -e, --erase erase EEPROM (fill with 0xff)\n" \
" -w, --write <filename> write EEPROM with image from filename\n" \
" -r, --read <filename> read EEPROM and save image to filename\n\n" \
"Example: fvflash bootrom.bin\n";
" -s, --size size of fv1 {24c32|24c64} default=24c32\n\n" \
"Example: fvflash bank.bin - writes bank.bin into fv1\n";
static struct option longopts[] = {
{"help", no_argument, 0, 'h'},
@ -65,6 +72,7 @@ int main(int argc, char **argv) {
{0, 0, 0, 0}
};
int32_t last_optidx = 0;
while (TRUE) {
int32_t optidx = 0;
int8_t c = getopt_long(argc,argv,"hdes:r:", longopts, &optidx);
@ -97,30 +105,28 @@ int main(int argc, char **argv) {
}
break;
default:
if(!operation) {
operation = 'w';
filename = (char *) malloc(strlen(argv[optidx])+1);
strcpy(filename, optarg);
} else {
fprintf(stderr, "Conflicting command line options\n");
goto shutdown;
}
break;
case '?': fprintf(stdout, "%s", version_msg);
case '?': fprintf(stdout, "%s\bn", version_msg);
fprintf(stderr, "%s", usage_msg);
goto shutdown;
}
last_optidx = optidx;
}
if(!operation) {
if(argc < 2) {
fprintf(stderr, "%s", usage_msg);
goto shutdown;
}
printf("writing %s\n", argv[argc-1]);
operation = 'w';
filename = (char *) malloc(strlen(argv[argc-1])+1);
strcpy(filename, argv[argc-1]);
}
debugout = (debug == TRUE) ? stdout : fopen("/dev/null","w");
verbout = (verbose == TRUE) ? stdout : fopen("/dev/null","w");
fprintf(debugout, "Debug Enabled\n");
if(!operation) {
fprintf(stderr, "%s\n%s", version_msg, usage_msg);
goto shutdown;
}
if(eepromsize <= 0) {
fprintf(stderr, "Invalid EEPROM size\n");
goto shutdown;

Loading…
Cancel
Save