Implement and "immediate mode" for file input - this allows one to

specify byte values on the command line instead of via a file.  This
can be good for specifying fuse bytes and eliminates the need to
create single-byte files or using interactive terminal mode for these
single-byte memories.  Requested by several folks on the mailing list.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@317 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Brian S. Dean 2003-04-19 18:41:35 +00:00
parent 5383559605
commit f931f8cc72
4 changed files with 77 additions and 19 deletions

View File

@ -250,6 +250,10 @@ Intel Hex
Motorola S-record
.It Ar r
raw binary; little-endian byte order, in the case of the flash ROM data
.It Ar m
immediate; actual byte values specified on the command line, seperated
by commas or spaces. This is good for programming fuse bytes without
having to create a single-byte file or enter terminal mode.
.It Ar a
auto detect; valid for input only, and only if the input is not
provided at

View File

@ -728,6 +728,49 @@ int fileio_rbin(struct fioparms * fio,
}
int fileio_imm(struct fioparms * fio,
char * filename, FILE * f, unsigned char * buf, int size)
{
int rc;
char * e, * p;
unsigned long b;
int loc;
switch (fio->op) {
case FIO_READ:
loc = 0;
p = strtok(filename, " ,");
while (p != NULL && loc < size) {
b = strtoul(p, &e, 0);
if (*e != 0) {
fprintf(stderr,
"%s: invalid byte value (%s) specified for immediate mode\n",
progname, p);
return -1;
}
buf[loc++] = b;
p = strtok(NULL, " ,");
rc = loc;
}
break;
default:
fprintf(stderr, "%s: fileio: invalid operation=%d\n",
progname, fio->op);
return -1;
}
if (rc < 0 || (fio->op == FIO_WRITE && rc < size)) {
fprintf(stderr,
"%s: %s error %s %s: %s; %s %d of the expected %d bytes\n",
progname, fio->iodesc, fio->dir, filename, strerror(errno),
fio->rw, rc, size);
return -1;
}
return rc;
}
int fileio_ihex(struct fioparms * fio,
char * filename, FILE * f, unsigned char * buf, int size)
{
@ -907,6 +950,18 @@ int fileio(int op, char * filename, FILEFMT format,
if (rc < 0)
return -1;
/* point at the requested memory buffer */
buf = mem->buf;
if (fio.op == FIO_READ)
size = mem->size;
if (fio.op == FIO_READ) {
/* 0xff fill unspecified memory */
for (i=0; i<size; i++) {
buf[i] = 0xff;
}
}
if (strcmp(filename, "-")==0) {
if (fio.op == FIO_READ) {
fname = "<stdin>";
@ -919,24 +974,7 @@ int fileio(int op, char * filename, FILEFMT format,
}
else {
fname = filename;
f = fopen(fname, fio.mode);
if (f == NULL) {
fprintf(stderr, "%s: can't open %s file %s: %s\n",
progname, fio.iodesc, fname, strerror(errno));
return -1;
}
}
/* point at the requested memory buffer */
buf = mem->buf;
if (fio.op == FIO_READ)
size = mem->size;
if (fio.op == FIO_READ) {
/* 0xff fill unspecified memory */
for (i=0; i<size; i++) {
buf[i] = 0xff;
}
f = NULL;
}
if (format == FMT_AUTO) {
@ -952,6 +990,16 @@ int fileio(int op, char * filename, FILEFMT format,
progname, fio.iodesc, fname, fmtstr(format));
}
if (format != FMT_IMM) {
fname = filename;
f = fopen(fname, fio.mode);
if (f == NULL) {
fprintf(stderr, "%s: can't open %s file %s: %s\n",
progname, fio.iodesc, fname, strerror(errno));
return -1;
}
}
switch (format) {
case FMT_IHEX:
rc = fileio_ihex(&fio, fname, f, buf, size);
@ -965,6 +1013,10 @@ int fileio(int op, char * filename, FILEFMT format,
rc = fileio_rbin(&fio, fname, f, buf, size);
break;
case FMT_IMM:
rc = fileio_imm(&fio, fname, f, buf, size);
break;
default:
fprintf(stderr, "%s: invalid %s file format: %d\n",
progname, fio.iodesc, format);

View File

@ -26,7 +26,8 @@ typedef enum {
FMT_AUTO,
FMT_SREC,
FMT_IHEX,
FMT_RBIN
FMT_RBIN,
FMT_IMM
} FILEFMT;
struct fioparms {

1
main.c
View File

@ -453,6 +453,7 @@ int main(int argc, char * argv [])
case 'i' : filefmt = FMT_IHEX; break;
case 'r' : filefmt = FMT_RBIN; break;
case 's' : filefmt = FMT_SREC; break;
case 'm' : filefmt = FMT_IMM; break;
break;
default :
fprintf(stderr, "%s: invalid file format \"%s\"\n\n",