2001-01-19 02:46:50 +00:00
|
|
|
/*
|
2003-02-08 04:17:25 +00:00
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
2003-02-06 19:08:33 +00:00
|
|
|
* Copyright (C) 2000, 2001, 2002, 2003 Brian S. Dean <bsd@bsdhome.com>
|
2001-01-19 02:46:50 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* 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.
|
2001-01-19 02:46:50 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* 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.
|
2001-01-19 02:46:50 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* 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
|
2001-01-19 02:46:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code to program an Atmel AVR AT90S device using the parallel port.
|
|
|
|
*
|
2003-02-21 21:19:56 +00:00
|
|
|
* For parallel port connected programmers, the pin definitions can be
|
|
|
|
* changed via a config file. See the config file for instructions on
|
|
|
|
* how to add a programmer definition.
|
|
|
|
*
|
2001-01-19 02:46:50 +00:00
|
|
|
*/
|
|
|
|
|
2003-02-14 20:34:03 +00:00
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
#include <stdio.h>
|
2001-09-19 17:04:25 +00:00
|
|
|
#include <stdlib.h>
|
2001-01-19 02:46:50 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
2001-01-26 20:34:08 +00:00
|
|
|
#include <time.h>
|
2001-01-19 02:46:50 +00:00
|
|
|
#include <unistd.h>
|
2001-09-19 17:04:25 +00:00
|
|
|
#include <ctype.h>
|
2003-02-22 16:45:13 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2001-01-19 02:46:50 +00:00
|
|
|
|
|
|
|
#include "avr.h"
|
2001-10-14 23:17:26 +00:00
|
|
|
#include "config.h"
|
2001-01-19 02:46:50 +00:00
|
|
|
#include "fileio.h"
|
2003-02-13 19:27:50 +00:00
|
|
|
#include "par.h"
|
2001-01-24 19:10:34 +00:00
|
|
|
#include "pindefs.h"
|
2001-01-19 02:46:50 +00:00
|
|
|
#include "ppi.h"
|
|
|
|
#include "term.h"
|
|
|
|
|
|
|
|
|
2003-02-06 05:45:06 +00:00
|
|
|
char * version = "3.1.0";
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2003-02-20 19:59:11 +00:00
|
|
|
int verbose; /* verbose output */
|
2001-01-19 02:46:50 +00:00
|
|
|
char * progname;
|
|
|
|
char progbuf[PATH_MAX]; /* temporary buffer of spaces the same
|
|
|
|
length as progname; used for lining up
|
|
|
|
multiline messages */
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
PROGRAMMER * pgm = NULL;
|
|
|
|
|
2002-08-01 02:06:48 +00:00
|
|
|
/*
|
|
|
|
* global options
|
|
|
|
*/
|
|
|
|
int do_cycles; /* track erase-rewrite cycles */
|
|
|
|
|
2001-09-19 17:04:25 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
/*
|
|
|
|
* usage message
|
|
|
|
*/
|
2001-10-13 03:13:13 +00:00
|
|
|
void usage(void)
|
2001-01-19 02:46:50 +00:00
|
|
|
{
|
2003-02-22 16:45:13 +00:00
|
|
|
printf(
|
2003-02-21 21:04:34 +00:00
|
|
|
"Usage: %s [options]\n"
|
|
|
|
"Options:\n"
|
|
|
|
" -p <partno> Required. Specify AVR device.\n"
|
|
|
|
" -C <config-file> Specify location of configuration file.\n"
|
|
|
|
" -c <programmer> Specify programmer type.\n"
|
|
|
|
" -P <port> Specify connection port.\n"
|
|
|
|
" -F Override invalid signature check.\n"
|
|
|
|
" -e Perform a chip erase.\n"
|
|
|
|
" -m <memtype> Memory type to operate on.\n"
|
|
|
|
" -i <filename> Write device. Specify an input file.\n"
|
|
|
|
" -o <filename> Read device. Specify an output file.\n"
|
|
|
|
" -f <format> Specify the file format.\n"
|
|
|
|
" -n Do not write anything to the device.\n"
|
|
|
|
" -V Do not verify.\n"
|
|
|
|
" -t Enter terminal mode.\n"
|
|
|
|
" -E <exitspec>[,<exitspec>] List programmer exit specifications.\n"
|
|
|
|
" -v Verbose output. An additional -v can be added.\n"
|
|
|
|
" -? Display this usage.\n"
|
|
|
|
"\navrdude project: <URL:http://savannah.nongnu.org/projects/avrdude>\n"
|
|
|
|
,progname);
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parse the -E string
|
|
|
|
*/
|
2001-10-13 03:13:13 +00:00
|
|
|
int getexitspecs(char *s, int *set, int *clr)
|
2001-01-19 02:46:50 +00:00
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
while ((cp = strtok(s, ","))) {
|
|
|
|
if (strcmp(cp, "reset") == 0) {
|
2003-02-13 19:27:50 +00:00
|
|
|
*clr |= par_getpinmask(pgm->pinno[PIN_AVR_RESET]);
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(cp, "noreset") == 0) {
|
2003-02-13 19:27:50 +00:00
|
|
|
*set |= par_getpinmask(pgm->pinno[PIN_AVR_RESET]);
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(cp, "vcc") == 0) {
|
2001-10-14 23:17:26 +00:00
|
|
|
if (pgm->pinno[PPI_AVR_VCC])
|
|
|
|
*set |= pgm->pinno[PPI_AVR_VCC];
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(cp, "novcc") == 0) {
|
2001-10-14 23:17:26 +00:00
|
|
|
if (pgm->pinno[PPI_AVR_VCC])
|
|
|
|
*clr |= pgm->pinno[PPI_AVR_VCC];
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
s = 0; /* strtok() should be called with the actual string only once */
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-19 17:04:25 +00:00
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
int read_config(char * file)
|
2001-09-19 17:04:25 +00:00
|
|
|
{
|
|
|
|
FILE * f;
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
f = fopen(file, "r");
|
2001-09-19 17:04:25 +00:00
|
|
|
if (f == NULL) {
|
|
|
|
fprintf(stderr, "%s: can't open config file \"%s\": %s\n",
|
2001-10-16 02:47:55 +00:00
|
|
|
progname, file, strerror(errno));
|
2001-09-19 17:04:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-02-22 16:45:13 +00:00
|
|
|
lineno = 1;
|
2001-10-14 23:17:26 +00:00
|
|
|
infile = file;
|
|
|
|
yyin = f;
|
2001-09-19 17:04:25 +00:00
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
yyparse();
|
2001-09-19 17:04:25 +00:00
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
fclose(f);
|
2001-09-19 17:04:25 +00:00
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
return 0;
|
2001-09-19 17:04:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-02-21 21:07:43 +00:00
|
|
|
void programmer_display(char * p)
|
2001-09-19 17:04:25 +00:00
|
|
|
{
|
2003-02-22 16:45:13 +00:00
|
|
|
fprintf(stderr, "%sProgrammer Type : %s\n", p, pgm->type);
|
|
|
|
fprintf(stderr, "%sDescription : %s\n", p, pgm->desc);
|
2001-12-29 21:37:20 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->display(pgm, p);
|
2001-09-19 17:04:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void verify_pin_assigned(int pin, char * desc)
|
|
|
|
{
|
2001-10-14 23:17:26 +00:00
|
|
|
if (pgm->pinno[pin] == 0) {
|
2001-09-19 17:04:25 +00:00
|
|
|
fprintf(stderr, "%s: error: no pin has been assigned for %s\n",
|
|
|
|
progname, desc);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
|
2003-02-21 21:07:43 +00:00
|
|
|
PROGRAMMER * locate_programmer(LISTID programmers, char * configid)
|
2001-10-14 23:17:26 +00:00
|
|
|
{
|
|
|
|
LNODEID ln1, ln2;
|
2001-10-16 02:50:27 +00:00
|
|
|
PROGRAMMER * p = NULL;
|
2001-10-14 23:17:26 +00:00
|
|
|
char * id;
|
|
|
|
int found;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
|
|
|
|
for (ln1=lfirst(programmers); ln1 && !found; ln1=lnext(ln1)) {
|
|
|
|
p = ldata(ln1);
|
|
|
|
for (ln2=lfirst(p->id); ln2 && !found; ln2=lnext(ln2)) {
|
|
|
|
id = ldata(ln2);
|
|
|
|
if (strcasecmp(configid, id) == 0)
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return p;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AVRPART * locate_part(LISTID parts, char * partdesc)
|
|
|
|
{
|
|
|
|
LNODEID ln1;
|
2001-10-16 02:50:27 +00:00
|
|
|
AVRPART * p = NULL;
|
2001-10-14 23:17:26 +00:00
|
|
|
int found;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
|
|
|
|
for (ln1=lfirst(parts); ln1 && !found; ln1=lnext(ln1)) {
|
|
|
|
p = ldata(ln1);
|
|
|
|
if ((strcasecmp(partdesc, p->id) == 0) ||
|
|
|
|
(strcasecmp(partdesc, p->desc) == 0))
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return p;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void list_parts(FILE * f, char * prefix, LISTID parts)
|
|
|
|
{
|
|
|
|
LNODEID ln1;
|
|
|
|
AVRPART * p;
|
|
|
|
|
|
|
|
for (ln1=lfirst(parts); ln1; ln1=lnext(ln1)) {
|
|
|
|
p = ldata(ln1);
|
2003-02-22 16:45:13 +00:00
|
|
|
fprintf(f, "%s%-4s = %-15s [%s:%d]\n",
|
|
|
|
prefix, p->id, p->desc, p->config_file, p->lineno);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void list_programmers(FILE * f, char * prefix, LISTID programmers)
|
|
|
|
{
|
|
|
|
LNODEID ln1;
|
|
|
|
PROGRAMMER * p;
|
|
|
|
|
|
|
|
for (ln1=lfirst(programmers); ln1; ln1=lnext(ln1)) {
|
|
|
|
p = ldata(ln1);
|
|
|
|
fprintf(f, "%s%-8s = %-30s [%s:%d]\n",
|
|
|
|
prefix, (char *)ldata(lfirst(p->id)), p->desc,
|
|
|
|
p->config_file, p->lineno);
|
2001-10-14 23:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-19 17:04:25 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
/*
|
|
|
|
* main routine
|
|
|
|
*/
|
2001-10-13 03:13:13 +00:00
|
|
|
int main(int argc, char * argv [])
|
2001-01-19 02:46:50 +00:00
|
|
|
{
|
|
|
|
int rc; /* general return code checking */
|
|
|
|
int exitrc; /* exit code for main() */
|
|
|
|
int i; /* general loop counter */
|
|
|
|
int ch; /* options flag */
|
|
|
|
int size; /* size of memory region */
|
|
|
|
int len; /* length for various strings */
|
2001-10-14 23:17:26 +00:00
|
|
|
struct avrpart * p; /* which avr part we are programming */
|
|
|
|
struct avrpart * v; /* used for verify */
|
2001-01-19 02:46:50 +00:00
|
|
|
int readorwrite; /* true if a chip read/write op was selected */
|
|
|
|
int ppidata; /* cached value of the ppi data register */
|
2001-01-20 16:34:28 +00:00
|
|
|
int vsize=-1; /* number of bytes to verify */
|
2001-11-21 02:46:55 +00:00
|
|
|
AVRMEM * sig; /* signature data */
|
2003-02-22 16:45:13 +00:00
|
|
|
struct stat sb;
|
2001-01-19 02:46:50 +00:00
|
|
|
|
|
|
|
/* options / operating mode variables */
|
2001-11-21 02:46:55 +00:00
|
|
|
char * memtype; /* "flash", "eeprom", etc */
|
2001-02-08 01:08:30 +00:00
|
|
|
int doread; /* 1=reading AVR, 0=writing AVR */
|
2001-01-19 02:46:50 +00:00
|
|
|
int erase; /* 1=erase chip, 0=don't */
|
|
|
|
char * outputf; /* output file name */
|
|
|
|
char * inputf; /* input file name */
|
|
|
|
int ovsigck; /* 1=override sig check, 0=don't */
|
2002-11-30 14:09:12 +00:00
|
|
|
char * port; /* device port (/dev/xxx) */
|
2001-01-19 02:46:50 +00:00
|
|
|
int terminal; /* 1=enter terminal mode, 0=don't */
|
|
|
|
FILEFMT filefmt; /* FMT_AUTO, FMT_IHEX, FMT_SREC, FMT_RBIN */
|
|
|
|
int nowrite; /* don't actually write anything to the chip */
|
|
|
|
int verify; /* perform a verify operation */
|
|
|
|
int ppisetbits; /* bits to set in ppi data register at exit */
|
|
|
|
int ppiclrbits; /* bits to clear in ppi data register at exit */
|
2001-09-21 03:27:20 +00:00
|
|
|
char * exitspecs; /* exit specs string from command line */
|
2003-02-21 21:07:43 +00:00
|
|
|
char * programmer; /* programmer id */
|
2001-10-14 23:17:26 +00:00
|
|
|
char * partdesc; /* part id */
|
2003-02-22 16:45:13 +00:00
|
|
|
char sys_config[PATH_MAX]; /* system wide config file */
|
|
|
|
char usr_config[PATH_MAX]; /* per-user config file */
|
2002-08-01 01:00:03 +00:00
|
|
|
int cycles; /* erase-rewrite cycles */
|
|
|
|
int set_cycles; /* value to set the erase-rewrite cycles to */
|
2002-12-12 03:59:28 +00:00
|
|
|
char * e; /* for strtol() error checking */
|
2003-02-22 16:45:13 +00:00
|
|
|
char * homedir;
|
2001-10-14 23:17:26 +00:00
|
|
|
|
|
|
|
progname = rindex(argv[0],'/');
|
|
|
|
if (progname)
|
|
|
|
progname++;
|
|
|
|
else
|
|
|
|
progname = argv[0];
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2003-02-21 18:46:51 +00:00
|
|
|
default_parallel[0] = 0;
|
|
|
|
default_serial[0] = 0;
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
init_config();
|
|
|
|
|
|
|
|
partdesc = NULL;
|
2001-09-19 17:04:25 +00:00
|
|
|
readorwrite = 0;
|
2003-02-21 18:46:51 +00:00
|
|
|
port = default_parallel;
|
2001-09-19 17:04:25 +00:00
|
|
|
outputf = NULL;
|
|
|
|
inputf = NULL;
|
|
|
|
doread = 1;
|
2001-11-21 02:46:55 +00:00
|
|
|
memtype = "flash";
|
2001-09-19 17:04:25 +00:00
|
|
|
erase = 0;
|
|
|
|
p = NULL;
|
|
|
|
ovsigck = 0;
|
|
|
|
terminal = 0;
|
|
|
|
filefmt = FMT_AUTO;
|
|
|
|
nowrite = 0;
|
2002-10-29 01:59:02 +00:00
|
|
|
verify = 1; /* on by default */
|
2001-09-21 03:27:20 +00:00
|
|
|
ppisetbits = 0;
|
|
|
|
ppiclrbits = 0;
|
|
|
|
exitspecs = NULL;
|
2001-10-14 23:17:26 +00:00
|
|
|
pgm = NULL;
|
2003-02-21 21:07:43 +00:00
|
|
|
programmer = default_programmer;
|
2001-10-13 03:12:52 +00:00
|
|
|
verbose = 0;
|
2002-08-01 01:00:03 +00:00
|
|
|
do_cycles = 0;
|
|
|
|
set_cycles = -1;
|
2001-09-19 17:04:25 +00:00
|
|
|
|
2003-02-22 16:45:13 +00:00
|
|
|
strcpy(sys_config, CONFIG_DIR);
|
|
|
|
i = strlen(sys_config);
|
|
|
|
if (i && (sys_config[i-1] != '/'))
|
|
|
|
strcat(sys_config, "/");
|
|
|
|
strcat(sys_config, "avrdude.conf");
|
|
|
|
|
|
|
|
usr_config[0] = 0;
|
|
|
|
homedir = getenv("HOME");
|
|
|
|
if (homedir != NULL) {
|
|
|
|
strcpy(usr_config, homedir);
|
|
|
|
i = strlen(usr_config);
|
|
|
|
if (i && (usr_config[i-1] != '/'))
|
|
|
|
strcat(usr_config, "/");
|
|
|
|
strcat(usr_config, ".avrduderc");
|
|
|
|
}
|
2001-09-19 17:04:25 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
len = strlen(progname) + 2;
|
|
|
|
for (i=0; i<len; i++)
|
|
|
|
progbuf[i] = ' ';
|
|
|
|
progbuf[i] = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check for no arguments
|
|
|
|
*/
|
|
|
|
if (argc == 1) {
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* process command line arguments
|
|
|
|
*/
|
2002-10-29 01:59:02 +00:00
|
|
|
while ((ch = getopt(argc,argv,"?c:C:eE:f:Fi:m:no:p:P:tvVyY:")) != -1) {
|
2001-01-19 02:46:50 +00:00
|
|
|
|
|
|
|
switch (ch) {
|
2003-02-21 21:07:43 +00:00
|
|
|
case 'c': /* programmer id */
|
|
|
|
programmer = optarg;
|
2001-09-19 17:04:25 +00:00
|
|
|
break;
|
|
|
|
|
2003-02-22 16:45:13 +00:00
|
|
|
case 'C': /* system wide configuration file */
|
|
|
|
strncpy(sys_config, optarg, PATH_MAX);
|
|
|
|
sys_config[PATH_MAX-1] = 0;
|
2001-09-19 17:04:25 +00:00
|
|
|
break;
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
case 'm': /* select memory type to operate on */
|
|
|
|
if ((strcasecmp(optarg,"e")==0)||(strcasecmp(optarg,"eeprom")==0)) {
|
2001-11-21 02:46:55 +00:00
|
|
|
memtype = "eeprom";
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
else if ((strcasecmp(optarg,"f")==0)||
|
|
|
|
(strcasecmp(optarg,"flash")==0)) {
|
2001-11-21 02:46:55 +00:00
|
|
|
memtype = "flash";
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-11-21 02:46:55 +00:00
|
|
|
memtype = optarg;
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
readorwrite = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F': /* override invalid signature check */
|
|
|
|
ovsigck = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
nowrite = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o': /* specify output file */
|
|
|
|
if (inputf || terminal) {
|
|
|
|
fprintf(stderr,"%s: -i, -o, and -t are incompatible\n\n", progname);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
doread = 1;
|
|
|
|
outputf = optarg;
|
|
|
|
if (filefmt == FMT_AUTO)
|
|
|
|
filefmt = FMT_RBIN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p' : /* specify AVR part */
|
2001-10-14 23:17:26 +00:00
|
|
|
partdesc = optarg;
|
2001-01-19 02:46:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'e': /* perform a chip erase */
|
|
|
|
erase = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'E':
|
2001-09-21 03:27:20 +00:00
|
|
|
exitspecs = optarg;
|
2001-01-19 02:46:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i': /* specify input file */
|
|
|
|
if (outputf || terminal) {
|
|
|
|
fprintf(stderr,"%s: -o, -i, and -t are incompatible\n\n", progname);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
doread = 0;
|
|
|
|
inputf = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f': /* specify file format */
|
|
|
|
if (strlen(optarg) != 1) {
|
|
|
|
fprintf(stderr, "%s: invalid file format \"%s\"\n",
|
|
|
|
progname, optarg);
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
switch (optarg[0]) {
|
|
|
|
case 'a' : filefmt = FMT_AUTO; break;
|
|
|
|
case 'i' : filefmt = FMT_IHEX; break;
|
|
|
|
case 'r' : filefmt = FMT_RBIN; break;
|
2003-02-20 03:53:49 +00:00
|
|
|
case 's' : filefmt = FMT_SREC; break;
|
2001-01-19 02:46:50 +00:00
|
|
|
break;
|
|
|
|
default :
|
|
|
|
fprintf(stderr, "%s: invalid file format \"%s\"\n\n",
|
|
|
|
progname, optarg);
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': /* enter terminal mode */
|
|
|
|
if (!((inputf == NULL)||(outputf == NULL))) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: terminal mode is not compatible with -i or -o\n\n",
|
|
|
|
progname);
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
terminal = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
2002-11-30 14:09:12 +00:00
|
|
|
port = optarg;
|
2001-01-19 02:46:50 +00:00
|
|
|
break;
|
|
|
|
|
2001-10-13 03:12:52 +00:00
|
|
|
case 'v':
|
|
|
|
verbose++;
|
2001-01-19 02:46:50 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-29 01:59:02 +00:00
|
|
|
case 'V':
|
|
|
|
verify = 0;
|
|
|
|
break;
|
|
|
|
|
2002-08-01 01:00:03 +00:00
|
|
|
case 'y':
|
|
|
|
do_cycles = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Y':
|
|
|
|
set_cycles = strtol(optarg, &e, 0);
|
|
|
|
if ((e == optarg) || (*e != 0)) {
|
|
|
|
fprintf(stderr, "%s: invalid cycle count '%s'\n",
|
|
|
|
progname, optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-08-01 02:06:48 +00:00
|
|
|
do_cycles = 1;
|
2002-08-01 01:00:03 +00:00
|
|
|
break;
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
case '?': /* help */
|
|
|
|
usage();
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: invalid option -%c\n\n", progname, ch);
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-10-13 03:12:52 +00:00
|
|
|
if (verbose) {
|
|
|
|
/*
|
|
|
|
* Print out an identifying string so folks can tell what version
|
|
|
|
* they are running
|
|
|
|
*/
|
2002-01-12 02:04:33 +00:00
|
|
|
fprintf(stderr,
|
2003-02-06 05:45:06 +00:00
|
|
|
"\n%s: Version %s\n"
|
|
|
|
"%sCopyright (c) 2000-2003 Brian Dean, bsd@bsdhome.com\n\n",
|
|
|
|
progname, version, progbuf);
|
2001-10-13 03:12:52 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 16:45:13 +00:00
|
|
|
if (verbose) {
|
|
|
|
fprintf(stderr, "%sSystem wide configuration file is \"%s\"\n",
|
|
|
|
progbuf, sys_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = read_config(sys_config);
|
2001-10-14 23:17:26 +00:00
|
|
|
if (rc) {
|
2003-02-22 16:45:13 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error reading system wide configuration file \"%s\"\n",
|
|
|
|
progname, sys_config);
|
2001-10-14 23:17:26 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2001-10-13 03:12:52 +00:00
|
|
|
|
2003-02-22 16:45:13 +00:00
|
|
|
if (usr_config[0] != 0) {
|
|
|
|
if (verbose) {
|
|
|
|
fprintf(stderr, "%sUser configuration file is \"%s\"\n",
|
|
|
|
progbuf, usr_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = stat(usr_config, &sb);
|
|
|
|
if ((rc < 0) || ((sb.st_mode & S_IFREG) == 0)) {
|
|
|
|
if (verbose) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%sUser configuration file does not exist or is not a "
|
|
|
|
"regular file, skipping\n",
|
|
|
|
progbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rc = read_config(usr_config);
|
|
|
|
if (rc) {
|
|
|
|
fprintf(stderr, "%s: error reading user configuration file \"%s\"\n",
|
|
|
|
progname, usr_config);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2003-02-21 21:07:43 +00:00
|
|
|
if (programmer[0] == 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"\n%s: no programmer has been specified on the command line "
|
|
|
|
"or the config file\n",
|
|
|
|
progname);
|
|
|
|
fprintf(stderr,
|
|
|
|
"%sSpecify a programmer using the -c option and try again\n\n",
|
|
|
|
progbuf);
|
|
|
|
exit(1);
|
2001-10-14 23:17:26 +00:00
|
|
|
}
|
2003-02-21 21:07:43 +00:00
|
|
|
|
|
|
|
pgm = locate_programmer(programmers, programmer);
|
|
|
|
if (pgm == NULL) {
|
2003-02-22 16:45:13 +00:00
|
|
|
fprintf(stderr,"\n");
|
2003-02-21 21:07:43 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Can't find programmer id \"%s\"\n",
|
|
|
|
progname, programmer);
|
2003-02-22 16:45:13 +00:00
|
|
|
fprintf(stderr,"\nValid programmers are:\n");
|
|
|
|
list_programmers(stderr, " ", programmers);
|
2003-02-21 21:07:43 +00:00
|
|
|
fprintf(stderr,"\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(programmer, "stk500") == 0) {
|
|
|
|
if (port == default_parallel) {
|
|
|
|
port = default_serial;
|
2001-10-14 23:17:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (partdesc == NULL) {
|
2001-01-19 02:46:50 +00:00
|
|
|
fprintf(stderr,
|
2003-02-22 16:45:13 +00:00
|
|
|
"%s: No AVR part has been specified, use \"-p Part\"\n\n",
|
2001-10-13 03:13:13 +00:00
|
|
|
progname);
|
2003-02-22 16:45:13 +00:00
|
|
|
fprintf(stderr,"Valid parts are:\n");
|
|
|
|
list_parts(stderr, " ", part_list);
|
2002-12-12 03:59:28 +00:00
|
|
|
fprintf(stderr, "\n");
|
2001-10-14 23:17:26 +00:00
|
|
|
exit(1);
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
|
|
|
|
p = locate_part(part_list, partdesc);
|
|
|
|
if (p == NULL) {
|
|
|
|
fprintf(stderr,
|
2003-02-22 16:45:13 +00:00
|
|
|
"%s: AVR Part \"%s\" not found.\n\n",
|
2001-10-14 23:17:26 +00:00
|
|
|
progname, partdesc);
|
2003-02-22 16:45:13 +00:00
|
|
|
fprintf(stderr,"Valid parts are:\n");
|
|
|
|
list_parts(stderr, " ", part_list);
|
2002-12-12 03:59:28 +00:00
|
|
|
fprintf(stderr, "\n");
|
2001-10-14 23:17:26 +00:00
|
|
|
exit(1);
|
2001-09-19 17:04:25 +00:00
|
|
|
}
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
|
2001-09-21 03:27:20 +00:00
|
|
|
if (exitspecs != NULL) {
|
2002-11-30 14:09:12 +00:00
|
|
|
if (strcmp(pgm->type, "PPI") != 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: WARNING: -E option is only valid with \"PPI\" "
|
|
|
|
"programmer types\n",
|
|
|
|
progname);
|
|
|
|
exitspecs = NULL;
|
|
|
|
}
|
|
|
|
else if (getexitspecs(exitspecs, &ppisetbits, &ppiclrbits) < 0) {
|
2001-09-21 03:27:20 +00:00
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-19 17:04:25 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
/*
|
|
|
|
* set up seperate instances of the avr part, one for use in
|
|
|
|
* programming, one for use in verifying. These are separate
|
|
|
|
* because they need separate flash and eeprom buffer space
|
|
|
|
*/
|
2001-10-14 23:17:26 +00:00
|
|
|
p = avr_dup_part(p);
|
|
|
|
v = avr_dup_part(p);
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
if (strcmp(pgm->type, "PPI") == 0) {
|
|
|
|
verify_pin_assigned(PIN_AVR_RESET, "AVR RESET");
|
|
|
|
verify_pin_assigned(PIN_AVR_SCK, "AVR SCK");
|
|
|
|
verify_pin_assigned(PIN_AVR_MISO, "AVR MISO");
|
|
|
|
verify_pin_assigned(PIN_AVR_MOSI, "AVR MOSI");
|
|
|
|
}
|
2001-09-19 17:04:25 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
/*
|
2002-11-30 14:09:12 +00:00
|
|
|
* open the programmer
|
2001-01-19 02:46:50 +00:00
|
|
|
*/
|
2003-02-21 18:46:51 +00:00
|
|
|
if (port[0] == 0) {
|
2003-02-21 21:07:43 +00:00
|
|
|
fprintf(stderr, "\n%s: no port has been specified on the command line "
|
|
|
|
"or the config file\n",
|
2003-02-21 18:46:51 +00:00
|
|
|
progname);
|
|
|
|
fprintf(stderr, "%sSpecify a port using the -P option and try again\n\n",
|
|
|
|
progbuf);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
fprintf(stderr, "%sUsing Port : %s\n", progbuf, port);
|
2003-02-21 21:07:43 +00:00
|
|
|
fprintf(stderr, "%sUsing Programmer : %s\n", progbuf, programmer);
|
2003-02-21 18:46:51 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->open(pgm, port);
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2002-12-01 06:35:18 +00:00
|
|
|
if (verbose) {
|
|
|
|
avr_display(stderr, p, progbuf, verbose);
|
|
|
|
fprintf(stderr, "\n");
|
2003-02-21 21:07:43 +00:00
|
|
|
programmer_display(progbuf);
|
2002-12-01 06:35:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
exitrc = 0;
|
|
|
|
|
2002-12-12 03:59:28 +00:00
|
|
|
/*
|
|
|
|
* allow the programmer to save its state
|
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
rc = pgm->save(pgm);
|
|
|
|
if (rc < 0) {
|
2001-01-19 02:46:50 +00:00
|
|
|
exitrc = 1;
|
|
|
|
ppidata = 0; /* clear all bits at exit */
|
|
|
|
goto main_exit;
|
|
|
|
}
|
2001-09-21 02:57:58 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
if (strcmp(pgm->type, "PPI") == 0) {
|
|
|
|
pgm->ppidata &= ~ppiclrbits;
|
|
|
|
pgm->ppidata |= ppisetbits;
|
|
|
|
}
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2002-11-23 00:47:29 +00:00
|
|
|
/*
|
2002-11-30 14:09:12 +00:00
|
|
|
* enable the programmer
|
2002-11-23 00:47:29 +00:00
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->enable(pgm);
|
2002-11-23 00:47:29 +00:00
|
|
|
|
2001-01-24 19:10:34 +00:00
|
|
|
/*
|
2002-11-30 14:09:12 +00:00
|
|
|
* turn off all the status leds
|
2001-01-24 19:10:34 +00:00
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->rdy_led(pgm, OFF);
|
|
|
|
pgm->err_led(pgm, OFF);
|
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
pgm->vfy_led(pgm, OFF);
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
/*
|
|
|
|
* initialize the chip in preperation for accepting commands
|
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
rc = pgm->initialize(pgm, p);
|
2001-01-19 02:46:50 +00:00
|
|
|
if (rc < 0) {
|
2001-10-13 03:13:13 +00:00
|
|
|
fprintf(stderr, "%s: initialization failed, rc=%d\n", progname, rc);
|
2001-01-19 02:46:50 +00:00
|
|
|
exitrc = 1;
|
|
|
|
goto main_exit;
|
|
|
|
}
|
|
|
|
|
2001-01-24 19:10:34 +00:00
|
|
|
/* indicate ready */
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->rdy_led(pgm, ON);
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2001-10-13 03:13:13 +00:00
|
|
|
fprintf(stderr,
|
2001-01-19 02:46:50 +00:00
|
|
|
"%s: AVR device initialized and ready to accept instructions\n",
|
2001-10-13 03:13:13 +00:00
|
|
|
progname);
|
2001-01-19 02:46:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Let's read the signature bytes to make sure there is at least a
|
|
|
|
* chip on the other end that is responding correctly. A check
|
|
|
|
* against 0xffffffff should ensure that the signature bytes are
|
|
|
|
* valid.
|
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
rc = avr_signature(pgm, p);
|
2001-11-21 02:46:55 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
fprintf(stderr, "%s: error reading signature data, rc=%d\n",
|
|
|
|
progname, rc);
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
sig = avr_locate_mem(p, "signature");
|
|
|
|
if (sig == NULL) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: WARNING: signature data not defined for device \"%s\"\n",
|
|
|
|
progname, p->desc);
|
2002-08-01 01:00:03 +00:00
|
|
|
}
|
2001-11-21 02:46:55 +00:00
|
|
|
|
|
|
|
if (sig != NULL) {
|
|
|
|
int ff;
|
|
|
|
|
|
|
|
fprintf(stderr, "%s: Device signature = 0x", progname);
|
|
|
|
ff = 1;
|
|
|
|
for (i=0; i<sig->size; i++) {
|
|
|
|
fprintf(stderr, "%02x", sig->buf[i]);
|
|
|
|
if (sig->buf[i] != 0xff)
|
|
|
|
ff = 0;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
if (ff) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Yikes! Invalid device signature.\n", progname);
|
|
|
|
if (!ovsigck) {
|
|
|
|
fprintf(stderr, "%sDouble check connections and try again, "
|
|
|
|
"or use -F to override\n"
|
|
|
|
"%sthis check.\n\n",
|
|
|
|
progbuf, progbuf);
|
|
|
|
exitrc = 1;
|
|
|
|
goto main_exit;
|
|
|
|
}
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 02:06:48 +00:00
|
|
|
if (set_cycles != -1) {
|
2002-11-30 14:09:12 +00:00
|
|
|
rc = avr_get_cycle_count(pgm, p, &cycles);
|
2002-11-06 02:19:57 +00:00
|
|
|
if (rc == 0) {
|
2002-08-01 02:06:48 +00:00
|
|
|
/*
|
|
|
|
* only attempt to update the cycle counter if we can actually
|
|
|
|
* read the old value
|
|
|
|
*/
|
|
|
|
cycles = set_cycles;
|
|
|
|
fprintf(stderr, "%s: setting erase-rewrite cycle count to %d\n",
|
|
|
|
progname, cycles);
|
2002-11-30 14:09:12 +00:00
|
|
|
rc = avr_put_cycle_count(pgm, p, cycles);
|
2002-08-01 02:06:48 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: WARNING: failed to update the erase-rewrite cycle "
|
|
|
|
"counter\n",
|
|
|
|
progname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
if (erase) {
|
|
|
|
/*
|
|
|
|
* erase the chip's flash and eeprom memories, this is required
|
|
|
|
* before the chip can accept new programming
|
|
|
|
*/
|
2001-10-13 03:13:13 +00:00
|
|
|
fprintf(stderr, "%s: erasing chip\n", progname);
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->chip_erase(pgm, p);
|
2001-10-13 03:13:13 +00:00
|
|
|
fprintf(stderr, "%s: done.\n", progname);
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
2002-08-01 02:06:48 +00:00
|
|
|
else if (set_cycles == -1) {
|
|
|
|
/*
|
|
|
|
* The erase routine displays this same information, so don't
|
|
|
|
* repeat it if an erase was done. Also, don't display this if we
|
|
|
|
* set the cycle count (due to -Y).
|
|
|
|
*
|
2002-11-06 02:19:57 +00:00
|
|
|
* see if the cycle count in the last four bytes of eeprom seems
|
2002-08-01 02:06:48 +00:00
|
|
|
* reasonable
|
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
rc = avr_get_cycle_count(pgm, p, &cycles);
|
2002-11-06 02:19:57 +00:00
|
|
|
if ((rc >= 0) && (cycles != 0xffffffff)) {
|
2002-08-01 02:06:48 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"%s: current erase-rewrite cycle count is %d%s\n",
|
|
|
|
progname, cycles,
|
|
|
|
do_cycles ? "" : " (if being tracked)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
|
|
|
|
if (!terminal && ((inputf==NULL) && (outputf==NULL))) {
|
|
|
|
/*
|
|
|
|
* Check here to see if any other operations were selected and
|
|
|
|
* generate an error message because if they were, we need either
|
2001-02-08 01:08:30 +00:00
|
|
|
* an input or an output file, but one was not selected.
|
2001-01-19 02:46:50 +00:00
|
|
|
* Otherwise, we just shut down.
|
|
|
|
*/
|
|
|
|
if (readorwrite) {
|
|
|
|
fprintf(stderr, "%s: you must specify an input or an output file\n",
|
|
|
|
progname);
|
|
|
|
exitrc = 1;
|
|
|
|
}
|
|
|
|
goto main_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (terminal) {
|
|
|
|
/*
|
|
|
|
* terminal mode
|
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
exitrc = terminal_mode(pgm, p);
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
else if (doread) {
|
|
|
|
/*
|
|
|
|
* read out the specified device memory and write it to a file
|
|
|
|
*/
|
|
|
|
fprintf(stderr, "%s: reading %s memory:\n",
|
2001-11-21 02:46:55 +00:00
|
|
|
progname, memtype);
|
2002-11-30 14:09:12 +00:00
|
|
|
rc = avr_read(pgm, p, memtype, 0, 1);
|
2001-01-20 16:34:28 +00:00
|
|
|
if (rc < 0) {
|
2001-01-19 02:46:50 +00:00
|
|
|
fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n",
|
2001-11-21 02:46:55 +00:00
|
|
|
progname, memtype, rc);
|
2001-01-19 02:46:50 +00:00
|
|
|
exitrc = 1;
|
|
|
|
goto main_exit;
|
|
|
|
}
|
2001-01-20 16:34:28 +00:00
|
|
|
size = rc;
|
2001-01-19 02:46:50 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "%s: writing output file \"%s\"\n",
|
|
|
|
progname, outputf);
|
2001-01-20 16:34:28 +00:00
|
|
|
rc = fileio(FIO_WRITE, outputf, filefmt, p, memtype, size);
|
2001-01-19 02:46:50 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr, "%s: terminating\n", progname);
|
|
|
|
exitrc = 1;
|
|
|
|
goto main_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* write the selected device memory using data from a file; first
|
|
|
|
* read the data from the specified file
|
|
|
|
*/
|
|
|
|
fprintf(stderr, "%s: reading input file \"%s\"\n",
|
|
|
|
progname, inputf);
|
2001-01-20 16:34:28 +00:00
|
|
|
rc = fileio(FIO_READ, inputf, filefmt, p, memtype, -1);
|
2001-01-19 02:46:50 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr, "%s: terminating\n", progname);
|
|
|
|
exitrc = 1;
|
|
|
|
goto main_exit;
|
|
|
|
}
|
|
|
|
size = rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* write the buffer contents to the selected memory type
|
|
|
|
*/
|
2002-07-27 20:55:01 +00:00
|
|
|
fprintf(stderr, "%s: writing %s (%d bytes):\n",
|
|
|
|
progname, memtype, size);
|
2001-01-19 02:46:50 +00:00
|
|
|
|
|
|
|
if (!nowrite) {
|
2002-11-30 14:09:12 +00:00
|
|
|
rc = avr_write(pgm, p, memtype, size, 1);
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* test mode, don't actually write to the chip, output the buffer
|
|
|
|
* to stdout in intel hex instead
|
|
|
|
*/
|
2001-01-20 16:34:28 +00:00
|
|
|
rc = fileio(FIO_WRITE, "-", FMT_IHEX, p, memtype, size);
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
2001-01-20 16:34:28 +00:00
|
|
|
if (rc < 0) {
|
2002-07-27 20:55:01 +00:00
|
|
|
fprintf(stderr, "%s: failed to write %s memory, rc=%d\n",
|
|
|
|
progname, memtype, rc);
|
2001-01-19 02:46:50 +00:00
|
|
|
exitrc = 1;
|
|
|
|
goto main_exit;
|
|
|
|
}
|
|
|
|
|
2001-01-20 16:34:28 +00:00
|
|
|
vsize = rc;
|
|
|
|
|
|
|
|
fprintf(stderr, "%s: %d bytes of %s written\n", progname,
|
2001-11-21 02:46:55 +00:00
|
|
|
vsize, memtype);
|
2001-01-20 16:34:28 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!doread && verify) {
|
|
|
|
/*
|
2001-10-13 03:12:52 +00:00
|
|
|
* verify that the in memory file (p->mem[AVR_M_FLASH|AVR_M_EEPROM])
|
2001-02-08 01:08:30 +00:00
|
|
|
* is the same as what is on the chip
|
2001-01-19 02:46:50 +00:00
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->vfy_led(pgm, ON);
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
fprintf(stderr, "%s: verifying %s memory against %s:\n",
|
2001-11-21 02:46:55 +00:00
|
|
|
progname, memtype, inputf);
|
2001-01-19 02:46:50 +00:00
|
|
|
fprintf(stderr, "%s: reading on-chip %s data:\n",
|
2001-11-21 02:46:55 +00:00
|
|
|
progname, memtype);
|
2002-11-30 14:09:12 +00:00
|
|
|
rc = avr_read(pgm, v, memtype, vsize, 1);
|
2001-01-20 16:34:28 +00:00
|
|
|
if (rc < 0) {
|
2001-01-19 02:46:50 +00:00
|
|
|
fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n",
|
2001-11-21 02:46:55 +00:00
|
|
|
progname, memtype, rc);
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->err_led(pgm, ON);
|
2001-01-19 02:46:50 +00:00
|
|
|
exitrc = 1;
|
|
|
|
goto main_exit;
|
|
|
|
}
|
2001-01-20 16:34:28 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "%s: verifying ...\n", progname);
|
|
|
|
rc = avr_verify(p, v, memtype, vsize);
|
|
|
|
if (rc < 0) {
|
2001-01-19 02:46:50 +00:00
|
|
|
fprintf(stderr, "%s: verification error; content mismatch\n",
|
|
|
|
progname);
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->err_led(pgm, ON);
|
2001-01-19 02:46:50 +00:00
|
|
|
exitrc = 1;
|
|
|
|
goto main_exit;
|
|
|
|
}
|
|
|
|
|
2001-01-20 16:34:28 +00:00
|
|
|
fprintf(stderr, "%s: %d bytes of %s verified\n",
|
2001-11-21 02:46:55 +00:00
|
|
|
progname, rc, memtype);
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->vfy_led(pgm, OFF);
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main_exit:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* program complete
|
|
|
|
*/
|
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->powerdown(pgm);
|
2001-09-21 03:27:20 +00:00
|
|
|
|
2002-12-12 03:59:28 +00:00
|
|
|
/*
|
|
|
|
* restore programmer state
|
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->restore(pgm);
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->disable(pgm);
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->rdy_led(pgm, OFF);
|
2001-02-08 01:42:09 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->close(pgm);
|
2001-01-19 02:46:50 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "\n%s done. Thank you.\n\n", progname);
|
|
|
|
|
|
|
|
return exitrc;
|
|
|
|
}
|
|
|
|
|