1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
* s51dude - A Downloader/Uploader for 8051 device programmers
* Copyright (C) 2008 Lucas Chiesa.
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <getopt.h>
#include <libintl.h>
#include "s51dude.h"
#include "usbtiny.h"
void get_params (int argc, char *argv[])
{
int short_option;
int option_index;
struct option long_options[] = {
{LC_LONG_LB1, no_argument, &lockbit1_flag, 1},
{LC_LONG_LB2, no_argument, &lockbit2_flag, 1},
{LC_LONG_LB3, no_argument, &lockbit3_flag, 1},
{LC_LONG_VERBOSE, no_argument, &verbose_flag, 1},
{LC_LONG_VERIFY, no_argument, &verify_flag, 0},
{LC_LONG_DRY_RUN, no_argument, &dry_run_flag, 1},
{LC_LONG_DEBUG, no_argument, &debug_flag, 1},
{LC_LONG_EEPROM, no_argument, &eeprom_flag, 1},
{LC_LONG_VERIFY_CHUNK, no_argument, &verify_chunk_flag, 1},
{LC_LONG_DEV, required_argument, NULL, LC_DEV},
{LC_LONG_ERASE, no_argument, NULL, LC_ERASE},
{LC_LONG_HELP, no_argument, NULL, LC_HELP},
{LC_LONG_VERSION, no_argument, NULL, LC_VERSION},
{LC_LONG_UPLOAD, required_argument, NULL, LC_UPLOAD},
{LC_LONG_READ, required_argument, NULL, LC_READ},
{LC_LONG_WLOCKBITS, no_argument, NULL, LC_WLOCKBITS},
{LC_LONG_RLOCKBITS, no_argument, NULL, LC_RLOCKBITS},
{0,0,0,0}
};
while (1) {
short_option = getopt_long (argc, argv, ALLOWED_SHORT_ARGUMENTS, long_options, &option_index);
if(short_option==-1) break;
switch (short_option) {
case LC_DEV:
load_dev(optarg);
break;
case LC_UPLOAD:
load_action(UPLOAD, optarg);
break;
case LC_READ:
load_action(READ, optarg);
break;
case LC_WLOCKBITS:
load_action(W_LOCKBITS, optarg);
break;
case LC_RLOCKBITS:
load_action(R_LOCKBITS, optarg);
break;
case LC_ERASE:
load_action(ERASE, optarg);
break;
case LC_HELP:
print_help();
exit(0);
break;
case LC_VERSION:
print_version();
exit(0);
break;
case '?':
exit_nice();
break;
}
}
}
void print_help (void)
{
printf("%s\n",_("s51dude [options] <target> <action>\n \
target: --part (-p) <part>\n \
supported part list:\n \
s8253\n \
s8252\n \
s52\n \
s53\n \
action: --upload (-u) <in-file>\n \
--read (-r) <out-file>\n \
--write-lbits (-w) <lock-bits>\n \
<lock-bits> can be any combination of the following:\n \
--LB1, --LB2, --LB3\n \
--read-lbits (-l)\n \
--erase (-e)\n \
Options:\n \
--eeprom: Change the target memory to EEPROM on some devices\n \
--no-verify: Disable verify.\n \
--verify-chunk: Verify reading after sending each chunk. Enable verbose to print each chunk.\n \
--dry-run: Test the action but don't do nothing.\n \
--verbose: Enable verbose output.\n \
--debug: Enable debug output.\n \
--help (-h): This help."));
}
void print_version (void)
{
printf("%s: %s\n",APPNAME,VERSION_STRING);
}
void load_action (actions modo, char archivo[])
{
if (options.operation != NAA) {
print_error(_("You can't do more than one action at the same time!"));
exit (1);
}
options.operation = modo;
if (archivo)
options.path=(char *) malloc ((strlen(archivo)+1)*sizeof(char));
if (archivo && !options.path) {
print_error (_("ERROR: Not enough memory."));
exit_nice();
} else if (options.path)
strcpy(options.path,archivo);
}
|