You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
5.0 KiB
141 lines
5.0 KiB
//
|
|
// ch341eeprom programmer version 0.1 (Beta)
|
|
//
|
|
// Programming tool for the 24Cxx serial EEPROMs using the Winchiphead CH341A
|
|
// IC
|
|
//
|
|
// (c) December 2011 asbokid <ballymunboy@gmail.com>
|
|
//
|
|
// 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
#define CH341TOOLVERSION "0.5-fv1-heckmod"
|
|
|
|
#include <getopt.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "libch341eeprom.h"
|
|
#include "libch341eeprom_internal.h"
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
uint8_t debug = FALSE;
|
|
uint8_t verbose = TRUE;
|
|
|
|
// in struct
|
|
int eepromsize = 4096;
|
|
char *filename = NULL;
|
|
char *eepromname = strdup("24c32");
|
|
char operation = 0;
|
|
|
|
static char
|
|
version_msg[] = "fvflash - an i2c EEPROM programming tool for the WCH CH341a IC\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"
|
|
"and you are welcome to redistribute it under certain conditions:\n"
|
|
"GNU GPL v3 License: http://www.gnu.org/licenses/gpl.html\n";
|
|
|
|
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 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' }, { "debug", no_argument, 0, 'd' },
|
|
{ "erase", no_argument, 0, 'e' }, { "size", required_argument, 0, 's' },
|
|
{ "read", required_argument, 0, 'r' }, { 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);
|
|
if (c == -1) {
|
|
break;
|
|
}
|
|
|
|
switch (c) {
|
|
case 'h':
|
|
fprintf(stdout, "%s\n%s", version_msg, usage_msg);
|
|
return 0;
|
|
case 'd':
|
|
debug = TRUE;
|
|
break;
|
|
case 's':
|
|
if ((eepromsize = parseEEPsize(optarg)) > 0) {
|
|
strcpy(eepromname, optarg);
|
|
} else {
|
|
fprintf(stderr, "Invalid EEPROM name %s \n", optarg);
|
|
exit(-4);
|
|
}
|
|
break;
|
|
case 'e':
|
|
if (!operation)
|
|
operation = 'e';
|
|
else {
|
|
fprintf(stderr, "Conflicting command line options\n");
|
|
exit(1);
|
|
}
|
|
break;
|
|
case 'r':
|
|
if (!operation) {
|
|
operation = 'r';
|
|
filename = (char *)malloc(strlen(optarg) + 1);
|
|
strcpy(filename, optarg);
|
|
} else {
|
|
fprintf(stderr, "Conflicting command line options\n");
|
|
exit(1);
|
|
}
|
|
break;
|
|
default:
|
|
case '?':
|
|
fprintf(stdout, "%s\bn", version_msg);
|
|
fprintf(stderr, "%s", usage_msg);
|
|
exit(2);
|
|
}
|
|
last_optidx = optidx;
|
|
}
|
|
|
|
if (!operation) {
|
|
if (argc < 2) {
|
|
fprintf(stderr, "%s", usage_msg);
|
|
exit(-3);
|
|
}
|
|
printf("writing %s\n", argv[argc - 1]);
|
|
operation = 'w';
|
|
filename = (char *)malloc(strlen(argv[argc - 1]) + 1);
|
|
strcpy(filename, argv[argc - 1]);
|
|
}
|
|
|
|
ch341_operation_desc opdesc;
|
|
opdesc.operation = operation;
|
|
opdesc.eepromname = eepromname;
|
|
opdesc.filename = filename;
|
|
ch341_operation(opdesc);
|
|
}
|
|
|