Browse Source

fv-1 specific defaults

master
heck 2 years ago
parent
commit
ff869bd768
  1. 27
      src/ch341eeprom.c

27
src/ch341eeprom.c

@ -32,15 +32,16 @@ FILE *debugout, *verbout;
uint8_t *readbuf = NULL; uint8_t *readbuf = NULL;
int main(int argc, char **argv) { int main(int argc, char **argv) {
int i, ret = 0, eepromsize = 0, bytesread = 0; int i, ret = 0, eepromsize = 4096, bytesread = 0;
uint8_t debug = FALSE, verbose = FALSE; uint8_t debug = FALSE, verbose = TRUE;
struct libusb_device_handle *devHandle = NULL; struct libusb_device_handle *devHandle = NULL;
char *filename = NULL, eepromname[12], operation = 0; char *filename = NULL, eepromname[12], operation = 0;
FILE *fp; FILE *fp;
static char version_msg[] = static char version_msg[] =
"ch341eeprom - an i2c EEPROM programming tool for the WCH CH341a IC\n" \ "fvflash - an i2c EEPROM programming tool for the WCH CH341a IC\n" \
"Version " CH341TOOLVERSION " copyright (c) 2011 asbokid <ballymunboy@gmail.com>\n\n" \ "Version " CH341TOOLVERSION " copyright (c) 2011 asbokid <ballymunboy@gmail.com>\n\n" \
"modified by <heck@heck.live> for the specific use case of fv-1 programming on macos\n\n" \
"This program comes with asbolutely no warranty; This is free software,\n" \ "This program comes with asbolutely no warranty; This is free software,\n" \
"and you are welcome to redistribute it under certain conditions:\n" \ "and you are welcome to redistribute it under certain conditions:\n" \
"GNU GPL v3 License: http://www.gnu.org/licenses/gpl.html\n"; "GNU GPL v3 License: http://www.gnu.org/licenses/gpl.html\n";
@ -48,36 +49,32 @@ int main(int argc, char **argv) {
static char usage_msg[] = static char usage_msg[] =
"Usage:\n" \ "Usage:\n" \
" -h, --help display this text\n" \ " -h, --help display this text\n" \
" -v, --verbose verbose output\n" \
" -d, --debug debug output\n" \ " -d, --debug debug output\n" \
" -s, --size size of EEPROM {24c32|24c64}\n" \ " -s, --size size of EEPROM {24c32|24c64} default=24c32\n" \
" -e, --erase erase EEPROM (fill with 0xff)\n" \ " -e, --erase erase EEPROM (fill with 0xff)\n" \
" -w, --write <filename> write EEPROM with image from filename\n" \ " -w, --write <filename> write EEPROM with image from filename\n" \
" -r, --read <filename> read EEPROM and save image to filename\n\n" \ " -r, --read <filename> read EEPROM and save image to filename\n\n" \
"Example: ch341eeprom -v -s 24c64 -w bootrom.bin\n"; "Example: fvflash bootrom.bin\n";
static struct option longopts[] = { static struct option longopts[] = {
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"verbose", no_argument, 0, 'v'},
{"debug", no_argument, 0, 'd'}, {"debug", no_argument, 0, 'd'},
{"erase", no_argument, 0, 'e'}, {"erase", no_argument, 0, 'e'},
{"size", required_argument, 0, 's'}, {"size", required_argument, 0, 's'},
{"read", required_argument, 0, 'r'}, {"read", required_argument, 0, 'r'},
{"write", required_argument, 0, 'w'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
while (TRUE) { while (TRUE) {
int32_t optidx = 0; int32_t optidx = 0;
int8_t c = getopt_long(argc,argv,"hvdes:w:r:", longopts, &optidx); int8_t c = getopt_long(argc,argv,"hdes:r:", longopts, &optidx);
if (c == -1) if (c == -1) {
break; break;
}
switch (c) { switch (c) {
case 'h': fprintf(stdout, "%s\n%s", version_msg, usage_msg); case 'h': fprintf(stdout, "%s\n%s", version_msg, usage_msg);
return 0; return 0;
case 'v': verbose = TRUE;
break;
case 'd': debug = TRUE; case 'd': debug = TRUE;
break; break;
case 's': if((eepromsize = parseEEPsize(optarg)) > 0) case 's': if((eepromsize = parseEEPsize(optarg)) > 0)
@ -99,16 +96,16 @@ int main(int argc, char **argv) {
goto shutdown; goto shutdown;
} }
break; break;
case 'w': if(!operation) { default:
if(!operation) {
operation = 'w'; operation = 'w';
filename = (char *) malloc(strlen(optarg)+1); filename = (char *) malloc(strlen(argv[optidx])+1);
strcpy(filename, optarg); strcpy(filename, optarg);
} else { } else {
fprintf(stderr, "Conflicting command line options\n"); fprintf(stderr, "Conflicting command line options\n");
goto shutdown; goto shutdown;
} }
break; break;
default :
case '?': fprintf(stdout, "%s", version_msg); case '?': fprintf(stdout, "%s", version_msg);
fprintf(stderr, "%s", usage_msg); fprintf(stderr, "%s", usage_msg);
goto shutdown; goto shutdown;

Loading…
Cancel
Save