Added "verify" command.

This commit is contained in:
Daniel Beer 2012-07-18 14:03:55 +12:00
parent 5584136b69
commit 65d15ef680
6 changed files with 46 additions and 7 deletions

View File

@ -488,6 +488,10 @@ Rename symbols by searching for those matching the given regular
expression and substituting the given string for the matched portion. The
symbols renamed are displayed, as well as a total count of all symbols
renamed.
.IP "\fBverify \fIfilename\fR"
Compare the contents of the given binary file to the chip memory. If any
differences are found, a message is printed for the first mismatched
byte.
.SH SUPPORTED CHIPS
The following chips are supported when using FET-compatible drivers:
.PP

View File

@ -120,6 +120,13 @@ const struct cmddb_record commands[] = {
"load <filename>\n"
" Flash the data contained in a binary file. Does not load symbols\n"
" or erase the device.\n"
},
{
.name = "verify",
.func = cmd_verify,
.help =
"verify <filename>\n"
" Compare the contents of the given binary file to the device memory.\n"
},
{
.name = "md",

View File

@ -534,7 +534,8 @@ static int do_cmd_prog(char **arg, int prog_flags)
return -1;
}
if (prog_flags && (binfile_info(in) & BINFILE_HAS_SYMS)) {
if ((prog_flags & PROG_WANT_ERASE) &&
(binfile_info(in) & BINFILE_HAS_SYMS)) {
stab_clear();
binfile_syms(in);
}
@ -544,7 +545,7 @@ static int do_cmd_prog(char **arg, int prog_flags)
if (prog_flush(&prog) < 0)
return -1;
printc("Done, %d bytes written\n", prog.total_written);
printc("Done, %d bytes total\n", prog.total_written);
if (device_ctl(DEVICE_CTL_RESET) < 0)
printc_err("warning: prog: "
@ -564,6 +565,11 @@ int cmd_load(char **arg)
return do_cmd_prog(arg, 0);
}
int cmd_verify(char **arg)
{
return do_cmd_prog(arg, PROG_VERIFY);
}
static int do_setbreak(device_bptype_t type, char **arg)
{
char *addr_text = get_arg(arg);

View File

@ -31,6 +31,7 @@ int cmd_dis(char **arg);
int cmd_hexout(char **arg);
int cmd_prog(char **arg);
int cmd_load(char **arg);
int cmd_verify(char **arg);
int cmd_setbreak(char **arg);
int cmd_setwatch(char **arg);
int cmd_setwatch_r(char **arg);

View File

@ -41,13 +41,33 @@ int prog_flush(struct prog_data *prog)
prog->have_erased = 1;
}
printc_dbg("Writing %4d bytes to %04x", prog->len, prog->addr);
printc_dbg("%s %4d bytes at %04x",
(prog->flags & PROG_VERIFY) ? "Verifying" : "Writing",
prog->len, prog->addr);
if (prog->section[0])
printc_dbg(" [section: %s]", prog->section);
printc_dbg("...\n");
if (device_writemem(prog->addr, prog->buf, prog->len) < 0)
return -1;
if (prog->flags & PROG_VERIFY) {
uint8_t cmp_buf[PROG_BUFSIZE];
int i;
if (device_readmem(prog->addr, cmp_buf, prog->len) < 0)
return -1;
for (i = 0; i < prog->len; i++)
if (cmp_buf[i] != prog->buf[i]) {
printc("\x1b[1mERROR:\x1b[0m "
"mismatch at %04x (read %02x, "
"expected %02x)\n",
prog->addr + i,
cmp_buf[i], prog->buf[i]);
return -1;
}
} else {
if (device_writemem(prog->addr, prog->buf, prog->len) < 0)
return -1;
}
prog->total_written += prog->len;
prog->addr += prog->len;
@ -65,7 +85,7 @@ int prog_feed(struct prog_data *prog, const struct binfile_chunk *ch)
* section.
*/
if (prog->len &&
((prog->addr + prog->len != ch->addr) ||
((prog->addr + prog->len != ch->addr) ||
strcmp(prog->section, section))) {
if (prog_flush(prog) < 0)
return -1;

View File

@ -36,7 +36,8 @@ struct prog_data {
address_t total_written;
};
#define PROG_WANT_ERASE 0x01
#define PROG_WANT_ERASE 0x01
#define PROG_VERIFY 0x02
void prog_init(struct prog_data *data, int flags);
int prog_feed(struct prog_data *data, const struct binfile_chunk *ch);