added verbose level in avrdude_message()

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1321 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Axel Wachtler
2014-06-13 20:07:40 +00:00
parent 471b504278
commit c6788bd795
45 changed files with 1854 additions and 2128 deletions

156
fileio.c
View File

@@ -125,7 +125,7 @@ static int b2ihex(unsigned char * inbuf, int bufsize,
unsigned char cksum;
if (recsize > 255) {
avrdude_message("%s: recsize=%d, must be < 256\n",
avrdude_message(MSG_INFO, "%s: recsize=%d, must be < 256\n",
progname, recsize);
return -1;
}
@@ -305,14 +305,14 @@ static int ihex2b(char * infile, FILE * inf,
continue;
rc = ihex_readrec(&ihex, buffer);
if (rc < 0) {
avrdude_message("%s: invalid record at line %d of \"%s\"\n",
avrdude_message(MSG_INFO, "%s: invalid record at line %d of \"%s\"\n",
progname, lineno, infile);
return -1;
}
else if (rc != ihex.cksum) {
avrdude_message("%s: ERROR: checksum mismatch at line %d of \"%s\"\n",
avrdude_message(MSG_INFO, "%s: ERROR: checksum mismatch at line %d of \"%s\"\n",
progname, lineno, infile);
avrdude_message("%s: checksum=0x%02x, computed checksum=0x%02x\n",
avrdude_message(MSG_INFO, "%s: checksum=0x%02x, computed checksum=0x%02x\n",
progname, ihex.cksum, rc);
return -1;
}
@@ -320,13 +320,13 @@ static int ihex2b(char * infile, FILE * inf,
switch (ihex.rectyp) {
case 0: /* data record */
if (fileoffset != 0 && baseaddr < fileoffset) {
avrdude_message("%s: ERROR: address 0x%04x out of range (below fileoffset 0x%x) at line %d of %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: address 0x%04x out of range (below fileoffset 0x%x) at line %d of %s\n",
progname, baseaddr, fileoffset, lineno, infile);
return -1;
}
nextaddr = ihex.loadofs + baseaddr - fileoffset;
if (nextaddr + ihex.reclen > bufsize) {
avrdude_message("%s: ERROR: address 0x%04x out of range at line %d of %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: address 0x%04x out of range at line %d of %s\n",
progname, nextaddr+ihex.reclen, lineno, infile);
return -1;
}
@@ -359,7 +359,7 @@ static int ihex2b(char * infile, FILE * inf,
break;
default:
avrdude_message("%s: don't know how to deal with rectype=%d "
avrdude_message(MSG_INFO, "%s: don't know how to deal with rectype=%d "
"at line %d of %s\n",
progname, ihex.rectyp, lineno, infile);
return -1;
@@ -369,14 +369,14 @@ static int ihex2b(char * infile, FILE * inf,
} /* while */
if (maxaddr == 0) {
avrdude_message("%s: ERROR: No valid record found in Intel Hex "
avrdude_message(MSG_INFO, "%s: ERROR: No valid record found in Intel Hex "
"file \"%s\"\n",
progname, infile);
return -1;
}
else {
avrdude_message("%s: WARNING: no end of file record found for Intel Hex "
avrdude_message(MSG_INFO, "%s: WARNING: no end of file record found for Intel Hex "
"file \"%s\"\n",
progname, infile);
@@ -397,7 +397,7 @@ static int b2srec(unsigned char * inbuf, int bufsize,
char * tmpl=0;
if (recsize > 255) {
avrdude_message("%s: ERROR: recsize=%d, must be < 256\n",
avrdude_message(MSG_INFO, "%s: ERROR: recsize=%d, must be < 256\n",
progname, recsize);
return -1;
}
@@ -430,7 +430,7 @@ static int b2srec(unsigned char * inbuf, int bufsize,
tmpl="S3%02X%08X";
}
else {
avrdude_message("%s: ERROR: address=%d, out of range\n",
avrdude_message(MSG_INFO, "%s: ERROR: address=%d, out of range\n",
progname, nextaddr);
return -1;
}
@@ -595,14 +595,14 @@ static int srec2b(char * infile, FILE * inf,
rc = srec_readrec(&srec, buffer);
if (rc < 0) {
avrdude_message("%s: ERROR: invalid record at line %d of \"%s\"\n",
avrdude_message(MSG_INFO, "%s: ERROR: invalid record at line %d of \"%s\"\n",
progname, lineno, infile);
return -1;
}
else if (rc != srec.cksum) {
avrdude_message("%s: ERROR: checksum mismatch at line %d of \"%s\"\n",
avrdude_message(MSG_INFO, "%s: ERROR: checksum mismatch at line %d of \"%s\"\n",
progname, lineno, infile);
avrdude_message("%s: checksum=0x%02x, computed checksum=0x%02x\n",
avrdude_message(MSG_INFO, "%s: checksum=0x%02x, computed checksum=0x%02x\n",
progname, srec.cksum, rc);
return -1;
}
@@ -629,16 +629,16 @@ static int srec2b(char * infile, FILE * inf,
break;
case 0x34: /* S4 - symbol record (LSI extension) */
avrdude_message("%s: ERROR: not supported record at line %d of %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: not supported record at line %d of %s\n",
progname, lineno, infile);
return -1;
case 0x35: /* S5 - count of S1,S2 and S3 records previously tx'd */
if (srec.loadofs != reccount){
avrdude_message("%s: ERROR: count of transmitted data records mismatch "
avrdude_message(MSG_INFO, "%s: ERROR: count of transmitted data records mismatch "
"at line %d of \"%s\"\n",
progname, lineno, infile);
avrdude_message("%s: transmitted data records= %d, expected "
avrdude_message(MSG_INFO, "%s: transmitted data records= %d, expected "
"value= %d\n",
progname, reccount, srec.loadofs);
return -1;
@@ -651,7 +651,7 @@ static int srec2b(char * infile, FILE * inf,
return maxaddr;
default:
avrdude_message("%s: ERROR: don't know how to deal with rectype S%d "
avrdude_message(MSG_INFO, "%s: ERROR: don't know how to deal with rectype S%d "
"at line %d of %s\n",
progname, srec.rectyp, lineno, infile);
return -1;
@@ -660,14 +660,14 @@ static int srec2b(char * infile, FILE * inf,
if (datarec == 1) {
nextaddr = srec.loadofs;
if (nextaddr < fileoffset) {
avrdude_message(msg, progname, nextaddr,
avrdude_message(MSG_INFO, msg, progname, nextaddr,
"(below fileoffset) ",
lineno, infile);
return -1;
}
nextaddr -= fileoffset;
if (nextaddr + srec.reclen > bufsize) {
avrdude_message(msg, progname, nextaddr+srec.reclen, "",
avrdude_message(MSG_INFO, msg, progname, nextaddr+srec.reclen, "",
lineno, infile);
return -1;
}
@@ -682,7 +682,7 @@ static int srec2b(char * infile, FILE * inf,
}
avrdude_message("%s: WARNING: no end of file record found for Motorola S-Records "
avrdude_message(MSG_INFO, "%s: WARNING: no end of file record found for Motorola S-Records "
"file \"%s\"\n",
progname, infile);
@@ -727,7 +727,7 @@ static Elf_Scn *elf_get_scn(Elf *e, Elf32_Phdr *ph, Elf32_Shdr **shptr)
Elf32_Shdr *sh;
size_t ndx = elf_ndxscn(s);
if ((sh = elf32_getshdr(s)) == NULL) {
avrdude_message("%s: ERROR: Error reading section #%u header: %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: Error reading section #%u header: %s\n",
progname, (unsigned int)ndx, elf_errmsg(-1));
continue;
}
@@ -745,7 +745,7 @@ static Elf_Scn *elf_get_scn(Elf *e, Elf32_Phdr *ph, Elf32_Shdr **shptr)
}
}
avrdude_message("%s: ERROR: Cannot find a matching section for "
avrdude_message(MSG_INFO, "%s: ERROR: Cannot find a matching section for "
"program header entry @p_vaddr 0x%x\n",
progname, ph->p_vaddr);
return NULL;
@@ -818,7 +818,7 @@ static int elf2b(char * infile, FILE * inf,
unsigned int low, high, foff;
if (elf_mem_limits(mem, p, &low, &high, &foff) != 0) {
avrdude_message("%s: ERROR: Cannot handle \"%s\" memory region from ELF file\n",
avrdude_message(MSG_INFO, "%s: ERROR: Cannot handle \"%s\" memory region from ELF file\n",
progname, mem->desc);
return -1;
}
@@ -836,7 +836,7 @@ static int elf2b(char * infile, FILE * inf,
strcmp(mem->desc, "apptable") == 0)) {
AVRMEM *flashmem = avr_locate_mem(p, "flash");
if (flashmem == NULL) {
avrdude_message("%s: ERROR: No \"flash\" memory region found, "
avrdude_message(MSG_INFO, "%s: ERROR: No \"flash\" memory region found, "
"cannot compute bounds of \"%s\" sub-region.\n",
progname, mem->desc);
return -1;
@@ -847,17 +847,17 @@ static int elf2b(char * infile, FILE * inf,
}
if (elf_version(EV_CURRENT) == EV_NONE) {
avrdude_message("%s: ERROR: ELF library initialization failed: %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: ELF library initialization failed: %s\n",
progname, elf_errmsg(-1));
return -1;
}
if ((e = elf_begin(fileno(inf), ELF_C_READ, NULL)) == NULL) {
avrdude_message("%s: ERROR: Cannot open \"%s\" as an ELF file: %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: Cannot open \"%s\" as an ELF file: %s\n",
progname, infile, elf_errmsg(-1));
return -1;
}
if (elf_kind(e) != ELF_K_ELF) {
avrdude_message("%s: ERROR: Cannot use \"%s\" as an ELF input file\n",
avrdude_message(MSG_INFO, "%s: ERROR: Cannot use \"%s\" as an ELF input file\n",
progname, infile);
goto done;
}
@@ -866,7 +866,7 @@ static int elf2b(char * infile, FILE * inf,
const char *id = elf_getident(e, &isize);
if (id == NULL) {
avrdude_message("%s: ERROR: Error reading ident area of \"%s\": %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: Error reading ident area of \"%s\": %s\n",
progname, infile, elf_errmsg(-1));
goto done;
}
@@ -882,7 +882,7 @@ static int elf2b(char * infile, FILE * inf,
}
if (id[EI_CLASS] != ELFCLASS32 ||
id[EI_DATA] != endianess) {
avrdude_message("%s: ERROR: ELF file \"%s\" is not a "
avrdude_message(MSG_INFO, "%s: ERROR: ELF file \"%s\" is not a "
"32-bit, %s-endian file that was expected\n",
progname, infile, endianname);
goto done;
@@ -890,13 +890,13 @@ static int elf2b(char * infile, FILE * inf,
Elf32_Ehdr *eh;
if ((eh = elf32_getehdr(e)) == NULL) {
avrdude_message("%s: ERROR: Error reading ehdr of \"%s\": %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: Error reading ehdr of \"%s\": %s\n",
progname, infile, elf_errmsg(-1));
goto done;
}
if (eh->e_type != ET_EXEC) {
avrdude_message("%s: ERROR: ELF file \"%s\" is not an executable file\n",
avrdude_message(MSG_INFO, "%s: ERROR: ELF file \"%s\" is not an executable file\n",
progname, infile);
goto done;
}
@@ -911,12 +911,12 @@ static int elf2b(char * infile, FILE * inf,
mname = "AVR";
}
if (eh->e_machine != machine) {
avrdude_message("%s: ERROR: ELF file \"%s\" is not for machine %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: ELF file \"%s\" is not for machine %s\n",
progname, infile, mname);
goto done;
}
if (eh->e_phnum == 0xffff /* PN_XNUM */) {
avrdude_message("%s: ERROR: ELF file \"%s\" uses extended "
avrdude_message(MSG_INFO, "%s: ERROR: ELF file \"%s\" uses extended "
"program header numbers which are not expected\n",
progname, infile);
goto done;
@@ -924,14 +924,14 @@ static int elf2b(char * infile, FILE * inf,
Elf32_Phdr *ph;
if ((ph = elf32_getphdr(e)) == NULL) {
avrdude_message("%s: ERROR: Error reading program header table of \"%s\": %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: Error reading program header table of \"%s\": %s\n",
progname, infile, elf_errmsg(-1));
goto done;
}
size_t sndx;
if (elf_getshdrstrndx(e, &sndx) != 0) {
avrdude_message("%s: ERROR: Error obtaining section name string table: %s\n",
avrdude_message(MSG_INFO, "%s: ERROR: Error obtaining section name string table: %s\n",
progname, elf_errmsg(-1));
sndx = 0;
}
@@ -945,11 +945,9 @@ static int elf2b(char * infile, FILE * inf,
ph[i].p_filesz == 0)
continue;
if (verbose >= 2) {
avrdude_message("%s: Considering PT_LOAD program header entry #%d:\n"
" p_vaddr 0x%x, p_paddr 0x%x, p_filesz %d\n",
progname, i, ph[i].p_vaddr, ph[i].p_paddr, ph[i].p_filesz);
}
avrdude_message(MSG_NOTICE2, "%s: Considering PT_LOAD program header entry #%d:\n"
" p_vaddr 0x%x, p_paddr 0x%x, p_filesz %d\n",
progname, i, ph[i].p_vaddr, ph[i].p_paddr, ph[i].p_filesz);
Elf32_Shdr *sh;
Elf_Scn *s = elf_get_scn(e, ph + i, &sh);
@@ -968,19 +966,15 @@ static int elf2b(char * infile, FILE * inf,
unsigned int lma;
lma = ph[i].p_paddr + sh->sh_offset - ph[i].p_offset;
if (verbose >= 2) {
avrdude_message("%s: Found section \"%s\", LMA 0x%x, sh_size %u\n",
progname, sname, lma, sh->sh_size);
}
avrdude_message(MSG_NOTICE2, "%s: Found section \"%s\", LMA 0x%x, sh_size %u\n",
progname, sname, lma, sh->sh_size);
if (lma >= low &&
lma + sh->sh_size < high) {
/* OK */
} else {
if (verbose >= 2) {
avrdude_message(" => skipping, inappropriate for \"%s\" memory region\n",
mem->desc);
}
avrdude_message(MSG_NOTICE2, " => skipping, inappropriate for \"%s\" memory region\n",
mem->desc);
continue;
}
/*
@@ -993,7 +987,7 @@ static int elf2b(char * infile, FILE * inf,
*/
if (mem->size != 1 &&
sh->sh_size > mem->size) {
avrdude_message("%s: ERROR: section \"%s\" does not fit into \"%s\" memory:\n"
avrdude_message(MSG_INFO, "%s: ERROR: section \"%s\" does not fit into \"%s\" memory:\n"
" 0x%x + %u > %u\n",
progname, sname, mem->desc,
lma, sh->sh_size, mem->size);
@@ -1002,22 +996,18 @@ static int elf2b(char * infile, FILE * inf,
Elf_Data *d = NULL;
while ((d = elf_getdata(s, d)) != NULL) {
if (verbose >= 2) {
avrdude_message(" Data block: d_buf %p, d_off 0x%x, d_size %d\n",
d->d_buf, (unsigned int)d->d_off, d->d_size);
}
avrdude_message(MSG_NOTICE2, " Data block: d_buf %p, d_off 0x%x, d_size %d\n",
d->d_buf, (unsigned int)d->d_off, d->d_size);
if (mem->size == 1) {
if (d->d_off != 0) {
avrdude_message("%s: ERROR: unexpected data block at offset != 0\n",
avrdude_message(MSG_INFO, "%s: ERROR: unexpected data block at offset != 0\n",
progname);
} else if (foff >= d->d_size) {
avrdude_message("%s: ERROR: ELF file section does not contain byte at offset %d\n",
avrdude_message(MSG_INFO, "%s: ERROR: ELF file section does not contain byte at offset %d\n",
progname, foff);
} else {
if (verbose >= 2) {
avrdude_message(" Extracting one byte from file offset %d\n",
foff);
}
avrdude_message(MSG_NOTICE2, " Extracting one byte from file offset %d\n",
foff);
mem->buf[0] = ((unsigned char *)d->d_buf)[foff];
mem->tags[0] = TAG_ALLOCATED;
rv = 1;
@@ -1028,10 +1018,8 @@ static int elf2b(char * infile, FILE * inf,
idx = lma - low + d->d_off;
if ((int)(idx + d->d_size) > rv)
rv = idx + d->d_size;
if (verbose >= 3) {
avrdude_message(" Writing %d bytes to mem offset 0x%x\n",
d->d_size, idx);
}
avrdude_message(MSG_DEBUG, " Writing %d bytes to mem offset 0x%x\n",
d->d_size, idx);
memcpy(mem->buf + idx, d->d_buf, d->d_size);
memset(mem->tags + idx, TAG_ALLOCATED, d->d_size);
}
@@ -1100,13 +1088,13 @@ static int fileio_rbin(struct fioparms * fio,
rc = fwrite(buf, 1, size, f);
break;
default:
avrdude_message("%s: fileio: invalid operation=%d\n",
avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n",
progname, fio->op);
return -1;
}
if (rc < 0 || (fio->op == FIO_WRITE && rc < size)) {
avrdude_message("%s: %s error %s %s: %s; %s %d of the expected %d bytes\n",
avrdude_message(MSG_INFO, "%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;
@@ -1135,7 +1123,7 @@ static int fileio_imm(struct fioparms * fio,
strtoul (p, &e, 0):
strtoul (p + 2, &e, 2);
if (*e != 0) {
avrdude_message("%s: invalid byte value (%s) specified for immediate mode\n",
avrdude_message(MSG_INFO, "%s: invalid byte value (%s) specified for immediate mode\n",
progname, p);
return -1;
}
@@ -1146,13 +1134,13 @@ static int fileio_imm(struct fioparms * fio,
}
break;
default:
avrdude_message("%s: fileio: invalid operation=%d\n",
avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n",
progname, fio->op);
return -1;
}
if (rc < 0 || (fio->op == FIO_WRITE && rc < size)) {
avrdude_message("%s: %s error %s %s: %s; %s %d of the expected %d bytes\n",
avrdude_message(MSG_INFO, "%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;
@@ -1182,7 +1170,7 @@ static int fileio_ihex(struct fioparms * fio,
break;
default:
avrdude_message("%s: invalid Intex Hex file I/O operation=%d\n",
avrdude_message(MSG_INFO, "%s: invalid Intex Hex file I/O operation=%d\n",
progname, fio->op);
return -1;
break;
@@ -1212,7 +1200,7 @@ static int fileio_srec(struct fioparms * fio,
break;
default:
avrdude_message("%s: ERROR: invalid Motorola S-Records file I/O "
avrdude_message(MSG_INFO, "%s: ERROR: invalid Motorola S-Records file I/O "
"operation=%d\n",
progname, fio->op);
return -1;
@@ -1232,7 +1220,7 @@ static int fileio_elf(struct fioparms * fio,
switch (fio->op) {
case FIO_WRITE:
avrdude_message("%s: ERROR: write operation not (yet) "
avrdude_message(MSG_INFO, "%s: ERROR: write operation not (yet) "
"supported for ELF\n",
progname);
return -1;
@@ -1243,7 +1231,7 @@ static int fileio_elf(struct fioparms * fio,
return rc;
default:
avrdude_message("%s: ERROR: invalid ELF file I/O "
avrdude_message(MSG_INFO, "%s: ERROR: invalid ELF file I/O "
"operation=%d\n",
progname, fio->op);
return -1;
@@ -1289,7 +1277,7 @@ static int fileio_num(struct fioparms * fio,
case FIO_WRITE:
break;
default:
avrdude_message("%s: fileio: invalid operation=%d\n",
avrdude_message(MSG_INFO, "%s: fileio: invalid operation=%d\n",
progname, fio->op);
return -1;
}
@@ -1319,7 +1307,7 @@ static int fileio_num(struct fioparms * fio,
return 0;
writeerr:
avrdude_message("%s: error writing to %s: %s\n",
avrdude_message(MSG_INFO, "%s: error writing to %s: %s\n",
progname, filename, strerror(errno));
return -1;
}
@@ -1346,7 +1334,7 @@ int fileio_setparms(int op, struct fioparms * fp,
break;
default:
avrdude_message("%s: invalid I/O operation %d\n",
avrdude_message(MSG_INFO, "%s: invalid I/O operation %d\n",
progname, op);
return -1;
break;
@@ -1385,7 +1373,7 @@ static int fmt_autodetect(char * fname)
f = fopen(fname, "rb");
#endif
if (f == NULL) {
avrdude_message("%s: error opening %s: %s\n",
avrdude_message(MSG_INFO, "%s: error opening %s: %s\n",
progname, fname, strerror(errno));
return -1;
}
@@ -1468,7 +1456,7 @@ int fileio(int op, char * filename, FILEFMT format,
mem = avr_locate_mem(p, memtype);
if (mem == NULL) {
avrdude_message("fileio(): memory type \"%s\" not configured for device \"%s\"\n",
avrdude_message(MSG_INFO, "fileio(): memory type \"%s\" not configured for device \"%s\"\n",
memtype, p->desc);
return -1;
}
@@ -1506,7 +1494,7 @@ int fileio(int op, char * filename, FILEFMT format,
if (format == FMT_AUTO) {
if (using_stdio) {
avrdude_message("%s: can't auto detect file format when using stdin/out.\n"
avrdude_message(MSG_INFO, "%s: can't auto detect file format when using stdin/out.\n"
"%s Please specify a file format and try again.\n",
progname, progbuf);
return -1;
@@ -1514,13 +1502,13 @@ int fileio(int op, char * filename, FILEFMT format,
format = fmt_autodetect(fname);
if (format < 0) {
avrdude_message("%s: can't determine file format for %s, specify explicitly\n",
avrdude_message(MSG_INFO, "%s: can't determine file format for %s, specify explicitly\n",
progname, fname);
return -1;
}
if (quell_progress < 2) {
avrdude_message("%s: %s file %s auto detected as %s\n",
avrdude_message(MSG_INFO, "%s: %s file %s auto detected as %s\n",
progname, fio.iodesc, fname, fmtstr(format));
}
}
@@ -1544,7 +1532,7 @@ int fileio(int op, char * filename, FILEFMT format,
if (!using_stdio) {
f = fopen(fname, fio.mode);
if (f == NULL) {
avrdude_message("%s: can't open %s file %s: %s\n",
avrdude_message(MSG_INFO, "%s: can't open %s file %s: %s\n",
progname, fio.iodesc, fname, strerror(errno));
return -1;
}
@@ -1568,7 +1556,7 @@ int fileio(int op, char * filename, FILEFMT format,
#ifdef HAVE_LIBELF
rc = fileio_elf(&fio, fname, f, mem, p, size);
#else
avrdude_message("%s: can't handle ELF file %s, "
avrdude_message(MSG_INFO, "%s: can't handle ELF file %s, "
"ELF file support was not compiled in\n",
progname, fname);
rc = -1;
@@ -1587,7 +1575,7 @@ int fileio(int op, char * filename, FILEFMT format,
break;
default:
avrdude_message("%s: invalid %s file format: %d\n",
avrdude_message(MSG_INFO, "%s: invalid %s file format: %d\n",
progname, fio.iodesc, format);
return -1;
}